My question with this program, Is how I should configure my code so I can pass the tests and for it to display the calendar as shown here:
Number of days: 30
Offset: 3
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
Number of days: 28
Offset: 0
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28
Number of days: 31
Offset: 6
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Tests
Starting Test 3
> Number of days: 31
> Offset: 6
> Su Mo Tu We Th Fr Sa
> 1 2 3 4 5 6 7\n
Exp: 1 2 3 4 5 6 7\n
> 8 9 10 11 12 13 14
> 15 16 17 18 19 20 21
> 22 23 24 25 26 27 28
> 29 30 31
Test 3 failed.
------------------------------------------------------------
------------------------------------------------------------
Starting Test 4
Here is another special case. Since the last day of the month also happens
to be the last day of the week, it is a common case to put an extra blank
line in the output. In other words, you put a newline in the output when
the day of the week is Saturday, and you put a newline in the output when
we get to the end of the month. You will need a special condition to check
that you are not on a Saturday when you display the end of the month newline
> Number of days: 30
> Offset: 4
> Su Mo Tu We Th Fr Sa
> 1 2
> 3 4 5 6 7 8 9
> 10 11 12 13 14 15 16
> 17 18 19 20 21 22 23
> 24 25 26 27 28 29 30
> \n
Exp: No output
Test 4 failed.
void displayTable(int numDays, int offset)
{
cout << " Su Mo Tu We Th Fr Sa\n";
for (int x = 0; x <= offset && offset <= 6; x++)
cout << " ";
for (int days = 1; days <= numDays; days++)
{
cout << " ";
if (days < 10)
cout << " ";
cout << days;
if ((offset + days + 1) % 7 == 0)
cout << "\n";
}
return;
}
int getOffset()
{
int offset;
cout << "Offset: ";
cin >> offset;
return offset;
}
int getNumDays()
{
int numDays;
cout << "Number of days: ";
cin >> numDays;
return numDays;
}
int main()
{
//Get the number of days
int numDays = getNumDays();
//Get the day offset
int offset = getOffset();
//Displays the result
displayTable(numDays, offset);
cout << "\n";
return 0;
}
Pd. I do not know what is wrong with the spacings of this editor. I can't get them to stay in place, but in every single one the numbers are expected to be aligned. Each of one them to their respective days, and the problem with my program is that when I set offset to 6 it starts it ignores my sat and keeps writing, what is expected is when we have offset of 6 it should start on Sunday.