Calendar Program I'm having trouble with
Hey everyone, beginner posting again. I am working on this for a school HW assignment. I have the code thus far to make a 'calendar' of sorts. I can't seem to get it to make a new line at the proper spot and continue counting the days of the month.
I can kind of see why. I know it has something to do with my displayTable function. I need it to make a new line before printing the date... It also has this problem when I input 6 for the offset, it will print the date below Sun, but then make a line.
I don't even know if I am asking the right question, it's hard for me to word. Anyway, I've been working on this staring at the screen for hours and can't seem to find a solution myself or through google. There are similar problems, but I just can't get mine to work.
Thank you for your help. I was even going to visit my tutor today about this problem, but he had to cancel. :frusty:
Code:
#include <iostream>
#include <iomanip>
using namespace std;
void displayHeader()
{
cout << " Su Mo Tu We Th Fr Sa" << endl;
return;
}
int getDays()
{
int days;
cout << "Number of days: ";
cin >> days;
return days;
}
int getOffset()
{
int offset;
cout << "Offset: ";
cin >> offset;
return offset;
}
void displayTable(int numDays, int offset)
{
// Variable
int days;
if (offset == 0) // Mon
cout << setw(4) << " ";
else if (offset == 1) // Tues
cout << setw(8) << " ";
else if (offset == 2) // Wed
cout << setw(12) << " ";
else if (offset == 3) // Thurs
cout << setw(16) << " ";
else if (offset == 4) // Fri
cout << setw(20) << " ";
else if (offset == 5) // Sat
cout << setw(24) << " ";
else (offset == 6) // Sun
;
for (days = 1; days <= numDays; days++)
{
cout << " " << setw(2) << days;
if ((days + offset) % 7 == 0)
cout << "\n";
}
cout << endl;
return;
}
int main()
{
int numDays = getDays();
int offset = getOffset();
displayHeader();
displayTable(numDays, offset);
return 0;
}
This is what the output is showing:
Code:
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