/* Program to find the day on a certain date entered by the user. ####################################################################### # (c) 2007 by Krishna Khanna # krishnakhanna@gmail.com # http://kkonline.org ####################################################################### */ # include # include # include # include void main() { clrscr(); int year,month,date,m,r,leap,yeard; char cont; textcolor(5); cout<<"\t\t"; cprintf(" THE DAY CALCULATOR"); textcolor(4); cout<>year; cprintf("ENTER THE NUMBER OF THE MONTH ( e.g. 7 FOR JULY ) : "); cin>>month; cprintf("ENTER THE DATE (1-31, 1-30, 1-29/28 depending on the month) : "); cin>>date; m=7;// 1 jan 2000 was a saturday if(year<2000) { yeard=2000-year; r=yeard/4; // calculation of number of leap years in between r=r+yeard; r=r%7; m-=r; } if(year>2000) { yeard=year-2000 ; if (yeard%4==0) r=(yeard/4)+1; else r=(yeard/4)+1 ; // calculation of number of leap years in between & 2000 was a leap year r=r+yeard ; r=r%7 ; m+=r ; m=m%7 ; } r=year%100; r%=4; // if r==0 then it is a leap year; if((r==0)&&(year>2000))m--; switch(month) { case 12: m+=(30%7);// nov has 30 days. case 11: m+=(31%7);// oct has 31 days. case 10: m+=(30%7);// sep has 30 days. case 9 : m+=(31%7);// aug has 31 days. case 8 : m+=(31%7);// july has 31 days. case 7 : m+=(30%7);// june has 30 days. case 6 : m+=(31%7);// may has 31 days. case 5 : m+=(30%7);// apr has 30 days. case 4 : m+=(31%7);// march has 31 days. case 3: { if(r==0) m+=(29%7); // in a leap year feb has one extra day. else m+=(28%7); } case 2: m+=(31%7); // jan has 31 days. } m=m+(date%7); m=m%7 ; m--; if(m<=0) m=7+m; // displaying result cout<<"\n\n\n\n\n"; textcolor(8); cout<>cont; cont=tolower(cont); } while(cont=='y'); getch(); }