//This program was written by Tiffany Overstreet on
//February 2, 2000. It will give the day of the week
//for a particular date.

#include <iostream.h>

void input(int &month, int &day, int &year);
//This function will get the month, day, and year from the user.
//The date must be between 1900 and 1999 inclusive.

void screen_data(int &month, int &day, int &year);
//This function will test the data to see if it is accurate.

void total(int &month, int &day, int &year, int &total);
//This function will get the total necessary to help the dermine
//the day of the week. It must have the information given by the
//user: the birth month, day, and year.

int remainder(int &total);
//This function will dermine the remainder when the total is
//divided by seven. The remainder will be returned to be used to
//find the day of the week.

void output(int remainder);
//This function will output the day of the week.

int main()
{
int month, day, year;
char decision;

cout<<"This program will return the day of a particular date"<<endl;
cout<<"between 1900 and 1999 inclusive."<<endl;

do
{
input(month, day, year);
screen_data(month, day, year);
cout<<endl<<"Would you like to continue? (y/n): ";
cin>>decision;
cout<<endl;
}
while (decision != 'n');

return 0;
}

void input(int &month, int &day, int &year)
{
cout<<"Please enter the month number: ";
cin>>dec>>month;
cout<<"Please enter the day: ";
cin>>dec>>day;
cout<<"Please enter the year: 19";
cin>>dec>>year;
}

void screen_data(int &month, int &day, int &year)
{
char bool;
char bool_month, bool_day, bool_year;
bool_month='v';
bool_day='v';
bool_year='v';
bool='v';

//This will test the month and day to make sure that they are
//valid. If the day or month is invalid then bool will be
//assigned to i for invalid.
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if ((day<1) || (day>31))
{
bool='i';
bool_day='i';
}
break;
case 4:
case 6:
case 9:
case 11:
if ((day<1) || (day>30))
{
bool='i';
bool_day='i';
}
break;

case 2:

if ((year%4==0) && (year>0))
{
if ((day<0) || (day>29))
bool='i';
bool_day='i';
}
else
{
if ((day<0) || (day>28))
bool='i';
bool_day='i';
}
break;

default:
bool='i';
bool_month='i';
break;
}

//This tests the year to make sure that it is between zero and 99.
//If the year is not valid then bool is assigned to i.
if ((year>99) || (year<0))
{
bool='i';
bool_year='i';
}
if (bool=='v')
{
int temp_total;
total(month, day, year, temp_total);
cout<<"For the date "<<month<<"/"<<day<<"/"<<1900+year;
output(remainder(temp_total));
}
else
{
cout<<"You have entered invalid data. Please try again.";
if (bool_month=='i')
cout<<endl<<"Hint: Try altering the month.";
if (bool_day=='i')
cout<<endl<<"Hint: Try altering the day.";
if (bool_year=='i')
cout<<endl<<"Hint: Try altering the year.";
cout<<endl;
}

}

void total(int &month, int &day, int &year, int &total)
{
//Step 1: Divide birthyear by four and put quotient in total.
total=(year/4);
//Step 2: Add last two digits of the birthyear to total.
total=(total+year);
//Step 3: Add last two digits of birthdate to total.
total=(total+day);
//Step 4: Use month number and add it to total.
switch (month)
{
case 1: total=total+1;break;
case 2: total=total+4;break;
case 3: total=total+4;break;
case 4: total=total;break;
case 5: total=total+2;break;
case 6: total=total+5;break;
case 7: total=total;break;
case 8: total=total+3;break;
case 9: total=total+6;break;
case 10: total=total+1;break;
case 11: total=total+4;break;
case 12: total=total+6;break;
default: cout<<"You did not enter a valid date.";break;
}
//Step 5: Calculate total for leap year.
if (year>0)
{
if ((year%4)>=0)
{
if ((month==1)||(month==2))
total=total-1;
}
}
else
total=total;
}

int remainder(int &total)
{
int remain;
remain=(total)%7;
return remain;
}

void output(int remainder)
{
cout<<" the day of the week was: ";
switch (remainder)
{
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";break;
default: cout<<"This didn't work.";break;
}
}

Go back to the start page for the Day Program.