WHy is my output so unorganized

done

 
   
Last edited on
I would start from here (line 94):
 
cout << "Sun " << "Mon " << "Tue " << "Wed " << "Thur " << "Fri " << "Sat " << endl;


That is almost a good start. All the columns are 4 characters wide. Except Thursday, which is 5 characters wide. So make a decision, settle on either 4 or 5 consistently across the board.

Then when printing the day numbers, don't try anything complicated to set the column width. Just put cout << setw(4) << DAY; or cout << setw(5) << DAY; depending on your preferred width.

A similar setw() when offsetting the first row and that should be about it. Note, you don't necessarily need a loop for that first line, just calculate the number of spaces required and a single cout << setw(n) << ' '; should do.

By the way, are you familiar with the idea of arrays? A lot of the code could probably be very much shorter if they were used rather than a long series of case: statements.
Last edited on
Yeah but i forgot everything about them. Oh and by the way should i take out the case statements from line 97-123. I tried using setw and playing around with it but still no like and the output went crazy lol.
Yes, I didn't understand the reason for lines 97-123, you could remove them.

Example of the use of arrays:
1
2
3
4
5
6
7
8
9
10
11
12
13
    int mnthDays[13] = { 0, 
        31, 28, 31, 30,
        31, 30, 31, 31,
        30, 31, 30, 31  
    };
    
    mnthDays[2] = ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? 29 : 28;
    
    for (int Month = 1; Month <= 12; Month++)
    {
        int numberofDays = mnthDays[Month];
		
		// etc. 

The month names are similar, but no need to adjust for February, so even simpler.

playing around with the code still cant get the dates under the corresponding weekdays ;/ why am i soooo dummmbbb
Topic archived. No new replies allowed.