Here is yet another day of the week program. This program will tell you the day of the week for any date from the 1700's to 2300's. I wrote this with what I was comfortable with, and it works. I am planning to revise this with some switch statements, and will probably put some of this into functions eventually, but for now it works.
My questions however:
Right now, you have to input whether or not it is a leap year. I have no clue how to make this automatic.
Also, I am having to input the calendar year in the hundreds, and input the last two digits of the year. I can't figure out how to make this one step, and then show this in this form : mm/dd/yy or yyyy.
anyways here is my code:
CODE
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
// variables
int calYear;
int yy;
int day;
int month;
int adjYear;
int modYear;
int modMonth;
int total;
string dayOfWeek;
char leapYear;
//inputs for calendar year
cout<<"Please enter the calendar year by the hundreds from 1700 to 2300"<<endl;
cout<<"Examples: 1700,1800,1900,2000,etc... >> ";
cin>>calYear;
cout<<endl<<endl;
//if statements for calYear adjustment
if(calYear==1700)
adjYear=4;
else
if(calYear==1800)
adjYear=2;
else
if(calYear==1900)
adjYear=0;
else
if(calYear==2000)
adjYear=6;
else
if(calYear==2100)
adjYear=4;
else
if(calYear==2200)
adjYear=2;
else
if(calYear==2300)
adjYear=0;
// input for last two digits of the year
cout<<"Please enter the last two digits of the year."<<endl;
cout<<"Examples: 59,69,79,89,00, etc... >> ";
cin>>yy;
cout<<endl<<endl;
//input for the day
cout<<"Please enter the day >> ";
cin>>day;
cout<<endl<<endl;
//input for month
cout<<"Please enter the month as a number"<<endl;
cout<<"Example: Jan=1, Dec=12 >> ";
cin>>month;
cout<<endl<<endl;
//leap year question
cout<<"Is the year you chose a leap year? 'y' or 'n' >> ";
cin>>leapYear;
cout<<endl<<endl;
//if statements for month adjustment
if (month==1)
modMonth=0;
else
if (month==2)
modMonth=3;
else
if (month==3)
modMonth=3;
else
if (month==4)
modMonth=6;
else
if (month==5)
modMonth=1;
else
if (month==6)
modMonth=4;
else
if (month==7)
modMonth=6;
else
if (month==8)
modMonth=2;
else
if (month==9)
modMonth=5;
else
if (month==10)
modMonth=0;
else
if (month==11)
modMonth=3;
else
if (month==12)
modMonth=5;
// math
modYear=(yy+(yy/4))%7;
total=(modYear+modMonth+day+adjYear)%7;
//if statements for day of the week string
if(total==0)
dayOfWeek="Sunday";
else
if(total==1)
dayOfWeek="Monday";
else
if(total==2)
dayOfWeek="Tuesday";
else
if(total==3)
dayOfWeek="Wednesday";
else
if(total==4)
dayOfWeek="Thursday";
else
if(total==5)
dayOfWeek="Friday";
else
if(total==6)
dayOfWeek="Saturday";
//if statement for leap year adjustment
if(leapYear=='y')
++total;
//output
cout<<"The day of the week for "<<month<<"/"<<day<<"/"<<yy<<" is a "<<dayOfWeek<<endl<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
I use the bloodshed compiler, if you are wondering.
Any suggestions you may have would be appreciated.
Thanks
Tony
This post has been edited by cboyd7539: 11 Mar, 2008 - 11:01 PM