int daysMonth(int month, int year)
{
int days = 0;
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
case 2:
if (isLeapYear(year))
days = 29;
else
days = 28;
break;
}
return days;
}
int computeOffset(int month, int year)
{
int offset = sumOfDays(month, year) % 7;
return offset;
}
void displayTable(int offset, int days)
{
int numbDays = days; //days come current daysMonth function
int slot = 1;
int day = -offset;
if (day == -6)
{
day = 1;
}
cout << " Su Mo Tu We Th Fr Sa\n";
for (; day <= numbDays; day++, slot++) //numbDays is the # of days for the month //
{
cout << " ";
if (day <= 0)
cout << " ";
else
cout << setw(2) << day;
if (slot % 7 == 0)
cout << "\n";
}
if ((slot - 1) % 7 != 0)
cout << endl;
}
int main()
{
int month = getMonth();
int year = getYear();
currentMonth(month, year);
displayTable(offset, days);
return 0;
}
The online compiler sees your posted code differently:
In function 'int daysMonth(int, int)':
23:29: error: 'isLeapYear' was not declared in this scope
In function 'int computeOffset(int, int)':
34:38: error: 'sumOfDays' was not declared in this scope
In function 'void displayTable(int, int)':
47:4: error: 'cout' was not declared in this scope
56:24: error: 'setw' was not declared in this scope
61:15: error: 'endl' was not declared in this scope
In function 'int main()':
67:25: error: 'getMonth' was not declared in this scope
68:23: error: 'getYear' was not declared in this scope
69:28: error: 'currentMonth' was not declared in this scope
70:17: error: 'offset' was not declared in this scope
70:25: error: 'days' was not declared in this scope
Anyway, I do presume that you don't have global variables and thus we should be looking at this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// (presumed) function declarations
int getMonth();
int getYear();
void currentMonth(int, int);
void displayTable(int, int);
int main()
{
int month = getMonth();
int year = getYear();
currentMonth( month, year );
displayTable( offset, days ); //syntax error
return 0;
}
Your main() declares two variables: month and year. They are initialized and then used in currentMonth(). However, identifiers 'offset' and 'days' have not been declared anywhere (within scope).