Ok we have been creating this calendar in our intro to programming class for about a week or so, and right now I am stuck on getting the start day of each month. I was thinking it should be total days (days in month + total days from 1800 - year), plus 3 (the day that january 1800 started on), mod 7, but i cant get it to work for the life of me, any help would be dearly appreciated.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
bool isLeapYear(int yr);
int getYear();
int getMonth();
int getNoOfDaysInMonth(int mo, int yr);
int getTotalNoOfDays(int mo, int yr);
string getMonthName(int mo);
string getStartDay(int TotDays);
int main()
{
int mo;
int numOfDays;
int yr;
int TotDays;
string moName;
string dname;
// processing area
mo=getMonth();
yr=getYear();
//leapYear = isLeapYear(yr);
numOfDays = getNoOfDaysInMonth( mo, yr);
moName = getMonthName(mo);
TotDays = getTotalNoOfDays(mo,yr);
dname = getStartDay(TotDays);
cout <<"Name of month is = " << moName << '\n';
cout <<"Number of Days = " << numOfDays << '\n';
cout <<"Total number of days = " << TotDays <<'\n';
cout <<"The first day in the month of " << moName << " is " << dname << " . " << '\n' ;
char c;
cout << "Please press any key to continue." << '\n';
cin >> c;
return 0;
}
bool isLeapYear(int yr)
{
bool leapYear;
leapYear = ((yr % 4 == 0) && (yr % 100 != 0)) || (yr % 400 == 0);
return leapYear;
}
int getNoOfDaysInMonth(int mo, int yr)
{
if (mo==1||mo==3||mo==5||mo==7||
mo==8||mo==10||mo==12)
return 31;
if (mo==9||mo==4||mo==6||mo==11)
return 30;
if (isLeapYear(yr))
return 29;
else
return 28;
}
int getYear()
{
int yr;
cout << "Plese enter a year." << '\n';
cin >> yr;
return yr;
}
int getMonth()
{
int mo;
cout << "Please enter a month." << '\n';
cin >> mo;
return mo;
}
int getTotalNoOfDays(int mo, int yr)
{
int j;
int totDays=0;
for (j=1800; j <= yr; j++)
{
if (isLeapYear(yr))
totDays = totDays + 366;
else
totDays = totDays + 365;
}
for (j=1; j <= mo; j++)
{
totDays = totDays + getNoOfDaysInMonth(mo,yr);
}
return totDays;
}
string getMonthName(int mo)
{
switch (mo)
{
case 1:
return "January";
case 2:
return "February";
case 3:
return "March";
case 4:
return "April";
case 5:
return "May";
case 6:
return "June";
case 7:
return "July";
case 8:
return "August";
case 9:
return "September";
case 10:
return "October";
case 11:
return "November";
case 12:
return "December";
}
return "You must enter a number between 1 and 12.";
}
string getStartDay(int TotDays)
{
int wday;
string dname;
wday = (TotDays + 3) % 7;
if (wday == 2)
{
dname = "Sunday";
}
if (wday == 3)
{
dname = "Monday";
}
if (wday == 4)
{
dname = "Tuesday";
}
if (wday == 5)
{
dname = "Wednesday";
}
if (wday == 6)
{
dname = "Thursday";
}
if (wday == 0)
{
dname = "Friday";
}
if (wday == 1)
{
dname = "Saturday";
}
return dname ;
}