Calendar Program

I've been trying to get this stupid function to work for days and just cannot get it.

My display looks like this:
1
2
3
4
5
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


All I want it to do is have those last 4, 5, 6, and 7 wrap around to the next column. I've tried inserting "\n" different places, but cannot get it to work properly. Can anyone lend me any insight?

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
32
33
34
35
36
37
38
39
void displayTable(int numDays, int offset)
{
   //Declare Variables
   int days;
   int colCount = 0;

   //List the day headings
   cout << "  Su  Mo  Tu  We  Th  Fr  Sa\n";

   //Offset
   if (offset == 0)
      cout << setw(4)  << " ";
   else if (offset == 1)
      cout << setw(8)  << " ";
   else if (offset == 2)
      cout << setw(12) << " ";
   else if (offset == 3)
      cout << setw(16) << " ";
   else if (offset == 4)
      cout << setw(20) << " ";
   else if (offset == 5)
      cout << setw(24) << " ";
   else (offset == 6)
      ;

   //Displays number of days
   for (days = 1; days <= numDays; days++)
   {
      cout << "  " << setw(2) << days;
      if (days % 7 == 0)
         cout << "\n";
   }
   if (colCount == 7)
   {
      cout << endl;
      colCount = 0;
   }
   return;
}
You forgot to take into account the offset. You should also print newlines before printing the actual day - you want to wrap before it's too late, after all.

if ((days+offset) % 7 == 0)

You probably don't want to print a newline when the month starts with a sunday (offset=6) either, so you should handle that case.
Athar, you are the MAN! If I could right now, I would give you a giant hug. Thank you so much. :)
Topic archived. No new replies allowed.