Hello everyone I have a question regarding my code. The program is supposed to show 0-7 for the offset. This starts on a Sunday until Saturday. It is supposed to count the days and then use the % 7 to display those. So my question here is how to make the offset function work correctly. For example the offset should display 0 when you put for month 1 and year 1753, but if you put 2 and 1753 the offset should be 3
THIS IS MY CODE
int getMonth()
{
int month;
cout << "Enter a month number: ";
cin >> month;
while( month < 0 || month > 12)
{
cout << "Month must be between 1 and 12.\n"
<< "Enter a month number: ";
cin >> month;
}
return month;
}
int getYear()
{
int year;
cout << "Enter year: ";
cin >> year;
while ( year < 1753)
{
cout << "Year must be 1753 or later.\n"
<< "Enter year: ";
cin >> year;
}
return year;
}
bool isLeapYear(int year)
{
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return 366;
else 365;
}
int numDaysMonth(int year, int month)
{
int daysMonth;
if ( month == 1)
daysMonth = 31;
else if ( month == 2)
{
if (isLeapYear(year))
daysMonth = 29;
else
daysMonth = 28;
}
else if ( month == 3)
daysMonth = 31;
else if ( month == 4)
daysMonth = 30;
else if ( month == 5)
daysMonth = 31;
else if ( month == 6)
daysMonth = 30;
else if ( month == 7)
daysMonth = 31;
else if ( month == 8)
daysMonth = 31;
else if ( month == 9)
daysMonth = 30;
else if ( month == 10)
daysMonth = 31;
else if ( month == 11)
daysMonth = 30;
else if ( month == 12)
daysMonth = 31;
return daysMonth;
}
int computeOffset(int month, int year)
{
int numDays;
for (int yearCount = 1753; yearCount < year; yearCount++)
{
numDays += isLeapYear(year);