Calendar question

ok so two problems the first isn't a big deal because I'm slowly working it out (it is under the // basically need to give the user two chances to input correctly then close the program). The second is literally kicking my butt. I am able to output the calendar 80% correct except for the first line. Do i need to set the initial parameters to something different? because right now it seems to simply randomly place integers where it wants along the first line.

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
40
41
42
43
#include <iomanip>
#include <iostream>
using namespace std;

int main(void)
{
  int week;
  int month;

 if ((month>=28||month<=31)&&(week>=1||week<=7))
   {
     cout << "Enter the number of days in the month: \n";
     cout << "Enter day of week which month starts (Sun=1, Sat=7): \n";
     cin >> month;
     cin >> week;
     // if((month<28||month>31)&&(week<1||week>7))
     // {               
     // cout << "Enter a value in the range 28-31 and 1-7. \n";
     // }
     // if((month<28||month>31)&&(week<1||week>7))
     //  {
     //     cout << "ok so that is twice now and it is now going to close \n";
     //  }
     // trying to get the second loop to work
   }
    cout << "\nSun Mon Tue Wed Thu Fri Sat\n";
    for (int i =1; i<= week ; i++) // parameters for first week
      {
    cout << setw(3) << left << "";
      }
    for (week=1; week <= month; week++) // parameters for second week
    {
        cout << setw(4) << left << week << "";
        if (((week+month-1)%7)==0)
      
      {
            cout << endl;
          }
    }
    cout << endl;
    cin.ignore();
return 0;
}

Last edited on
I guess i should mention I know this can be done with a switch case statement, I also know that it can be done without one I simply cannot figure it out, and I see no point in making 15 lines for something that can be done a better way.
replace this code for line 27 to line 39 .
That is, the segment responsible for printing out the calender.

1
2
3
4
5
6
7
8
9
10
11
12
13
for(int i = 0; i < month; i++)
{
    if(i %7 == 0)
        cout<<endl;
    if(i < week)
    {
        cout<<setw(6)<<' ';
        ++month;	
    }
    else
        cout<<setw(6)<<i-(week-1);		
}
.

If you can arrange setw() arguments if the formatting does not fit yours.
Last edited on
Topic archived. No new replies allowed.