WHAT'S NEW?
Loading...

Membuat Program Kalender Seumur Hidup dengan C++

// Program Kalender Selamanya Menggunakan C++

#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
int nK=0;
void kabisat(int nT){
    if(nT%4==0){
        if(nT%100==0){if(nT%400==0){nK=1;}}
            else{nK=1;}
        cout<<nK;}
    }
int kodehari(int nT,int nJHS){
    int k,s;
    k=(nT-1)/4;
    s=(nT+k+nJHS)%7;
    return s;
    }
int main(){
    int nB,nJH,nJHS,nH,nKH,nHARI[7];
    string sNB;
    int nT;
    do{
    cout<<"Bulan = ";cin>>nB;
    if(nB<0||nB>12){cout<<"Input Error !!\n";}
    }while(nB<0||nB>12);
    cout<<"Tahun = ";cin>>nT;
    kabisat(nT);
    switch(nB)
        {
            case 1: sNB="Januari";nJH=31;nJHS=1;break;
            case 2: sNB="Februari";if(nK==0){nJH=28;}
                                    else {nJH=29;}
                                    nJHS=32;break;
            case 3: sNB="Maret";nJH=31;nJHS=60;break;
            case 4: sNB="April";nJH=30;nJHS=91;break;
            case 5: sNB="Mei";nJH=31;nJHS=121;break;
            case 6: sNB="Juni";nJH=30;nJHS=152;break;
            case 7: sNB="Juli";nJH=31;nJHS=182;break;
            case 8: sNB="Agustus";nJH=31;nJHS=213;break;
            case 9: sNB="September";nJH=30;nJHS=244;break;
            case 10: sNB="Oktober";nJH=31;nJHS=275;break;
            case 11: sNB="November";nJH=30;nJHS=305;break;
            case 12: sNB="Desember";nJH=31;nJHS=335;break;
        }
    if(nK==1&&nB!=1&&nB!=2){nJHS++;}
    nKH=kodehari(nT,nJHS);
    if(nKH<0){nKH=-nKH;}
    system("cls");
    cout<<sNB<<", "<<nT<<" Masehi\n\n\n";
    cout<<"Jum'at \tSabtu \tMinggu \tSenin \tSelasa \tRabu \tKamis\n\n\n";
    for(int i=1;i<=nKH;i++){cout<<"\t";}
    for(int i=1;i<=nJH;i++,nKH++){
        cout<<setw(3)<<i<<"\t";
        if(nKH-6==0){cout<<"\n\n";nKH=-1;}
        }
    cout<<endl;

 }

2 comments: Leave Your Comments