Calendar program

i had to make a program to print a calendar taking the input of number of days and the first day of the month from the user .
the sample output given in the question had no 0's and instead had blank spaces.
how do i remove the 0's from the unassigned positions in my calendar

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
#include <iostream>
using namespace std;

int calendar[6][7] ;
void cal(int y , int z) // y is number of days and z is the number corresponding 
{                              // to the first day
        int n = 1 ;
        for(int j=z-1;j<7;j++)
        {
            calendar[0][j] = n ;
            n++ ;
        }
        for(int i=1;i<6&&n<=y;i++)
        {
            for(int k=0;k<7&&n<=y;k++)
            {
                calendar[i][k] = n ;
                n++ ;
            }
        }
}

int main()
{   int d ;
    int day ;
    cout << "Enter number of days : " ;
    cin>> d ;
    cout<< "Enter first day of the month(1 for monday 7 for sunday..) : " ;
    cin>> day ; cout<<"\n" ;
    cal(d,day) ;
    cout<<"M       T       W       T       F       S       S"<< endl;
    cout<<"\n" ;
    for(int i=0 ;i<6 ;i++)
    {
        for(int j=0 ;j<7;j++)
        {
            cout<<calendar[i][j]<<"\t" ;
        }
        cout<<""<< endl ;
    }

}
Last edited on
Topic archived. No new replies allowed.