Formatting a calendar program with a 2-D array

Hey all, I am working on a calendar program using a 2-d array. I have it relatively complete, but cannot get it to print out correctly. I need to make it print out like a traditional calendar, i.e. the month starts Wednesday, my code is looking like this:

1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18

But I have to get the numbers to all line up perfectly in their formatting, in a neat, calendar like style. This is indeed homework, but I have tried and tried and tried. My professor simply said :

-there is no number at all (like when the month begins on Friday); so how many spaces must you display for each number which is missing?

-there is a single digit rather than two digits; so how many spaces must you display for a single number rather than two numbers?

I am really confused, any advice would be awesome. Code below.

I am using a 2-D array [5] [7]. This is my first time using one.


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
 
        
        cout << "\n" << monthName << endl;
        cout << "\n";
        
        for (int xx =0; xx < 5; xx++)    {
            
            
            
            for(int yy = 0; yy < 7; yy++)
                
            {
                
                if(month[xx][yy] == 0)
                    
                    cout << "    ";
                
                else
                    
                    cout << month[xx][yy] << " ";
                
            }
            
            cout << "\n ";
        }
Last edited on
I tried using conditionals to control the flow even more, but am still coming up empty...any advice? Sorry for the odd formatting above, it keeps getting wonky for some reason.
Topic archived. No new replies allowed.