|
|
|
Return
to the BobbyGriggs.com C++ Nook
// Program name: Birthday
// Purpose: To compute the day of the week an individual was born
// on by entering his or her birth date.
// Win32 console application
#include < iostream.h >
#include < stdio.h >
void Input_birth_date(int &mm,int &dd,int &yy);
int Compute_total(int mm,int dd,int yy);
void Display_day(int t,int yy);
void main()
{
int month,day,year,total;
Input_birth_date(month,day,year);
total = Compute_total(month,day,year);
Display_day(total,year);
return;
}
void Input_birth_date(int &mm,int &dd,int &yy)
{
cout << "Enter individual's birth date" << endl << endl; cout << "Month (MM): "; cin>> mm;
cout << "Day (DD): "; cin>> dd;
cout << "Year (YYYY): "; cin>> yy;
cout << endl; return; } int Compute_total(int mm,int dd,int yy) { int t,r; t="0;" if (yy> 1900)
{
yy = yy - 1900;
t = yy / 4;
t = t + yy;
t = t + dd;
switch (mm)
{ // begin switch statement
case 1 :
t = t + 1;
break;
case 2 :
case 3 :
t = t + 4;
break;
case 4 :
break;
case 5 :
t = t + 2;
break;
case 6 :
t = t + 5;
break;
case 7 :
break;
case 8 :
t = t + 3;
break;
case 9 :
t = t + 6;
break;
case 10 :
t = t + 1;
break;
case 11 :
t = t + 4;
break;
case 12 :
t = t + 6;
} // end switch statement
if ((yy % 4) == 0)
if ((mm == 1) || (mm == 2))
t--;
}
else
yy = -1;
return t;
}
void Display_day(int t,int yy)
{
int rem;
if (yy == -1)
cout << "The birth year was prior to 1900." << endl << endl; else { cout << "You were born on "; rem="t" % 7; switch (rem) { case 1 : cout << "Sunday!"; break; case 2 : cout << "Monday!"; break; case 3 : cout << "Tuesday!"; break; case 4 : cout << "Wednesday!"; break; case 5 : cout << "Thursday!"; break; case 6 : cout << "Friday!"; break; case 0 : cout << "Saturday!"; } cout << endl << endl; } cout << "Hit enter to continue ... " << endl; getchar(); return; }
|