Hi,
This is what I have done so far (below)
I'm having a problem with the spacing as shown in the output (below the code)
Can anyone please help me fix the spacing?
Thank You!!
************************************************** **************
CODE:
#include <iostream>
using namespace std;
void question (int input);
void calendar (int year, int start_day);
void line_num (int count_days, int days_month);
bool leap_year (int year);
void nums_month (int count, int& days_month, int& prev_day);
void month_names (int count);
void day_names ();
void spacing (int start_day, int& count_col, int count, int& prev_spacing);
int input;
int start_day;
int days_month;
int year;
int prev_day;
int count_days = 1;
int count_col = 0;
int prev_spacing;
int main()
{
question(input);
calendar(year, start_day);
}
void question (int input)
{
cout << "Which year of the calendar do you want?" << endl;
cin >> year;
cout << "Which day do you want January 1st to start on?" << endl << "Ex: Sunday = 0, Monday = 1, Tuesday = 2, etc" << endl;
cin >> start_day;
}
void calendar (int year, int start_day)
{
int count;
for (count = 1; count <= 12; count++)
{
month_names (count);
day_names ();
nums_month(count, days_month, prev_day);
spacing (start_day, count_col, count, prev_spacing);
line_num (count_days, days_month);
}
}
void line_num (int count_days, int days_month)
{
while (count_days <= days_month)
{
if (count_col == 7)
{
cout << endl;
count_col = 0;
}
cout << " " << count_days << " ";
count_col++;
count_days++;
}
count_col = 0;
cout << endl << endl;
}
bool leap_year (int year)
{
if (year % 400 == 0)
{
return true;
}
if (year % 100 == 0)
{
return false;
}
if (year % 4 == 0)
{
return true;
}
return false;
}
void nums_month (int count, int& days_month, int& prev_day)
{
switch (count)
{
case 1:
days_month = 31;
break;
case 2:
if (leap_year(year))
days_month = 29;
if (!leap_year(year))
days_month = 28;
prev_day = 31;
break;
case 3:
days_month = 31;
if (leap_year(year))
prev_day = 29;
if (!leap_year(year))
prev_day = 28;
break;
case 4:
days_month = 30;
prev_day = 31;
break;
case 5:
days_month = 31;
prev_day = 30;
break;
case 6:
days_month = 30;
prev_day = 31;
break;
case 7:
days_month = 31;
prev_day = 30;
break;
case 8:
days_month = 31;
prev_day = 31;
break;
case 9:
days_month = 30;
prev_day = 31;
break;
case 10:
days_month = 31;
prev_day = 30;
break;
case 11:
days_month = 30;
prev_day = 31;
break;
case 12:
days_month = 31;
prev_day = 30;
break;
}
}
void month_names (int count)
{
switch (count)
{
case 1:
cout << " January" << endl;
break;
case 2:
cout << " February" << endl;
break;
case 3:
cout << " March" << endl;
break;
case 4:
cout << " April" << endl;
break;
case 5:
cout << " May" << endl;
break;
case 6:
cout << " June" << endl;
break;
case 7:
cout << " July" << endl;
break;
case 8:
cout << " August" << endl;
break;
case 9:
cout << " September" << endl;
break;
case 10:
cout << " October" << endl;
break;
case 11:
cout << " November" << endl;
break;
case 12:
cout << " December" << endl;
break;
}
}
void day_names ()
{
cout << " S M TU W TH F S " << endl;
}
void spacing (int start_day, int& count_col, int count, int& prev_spacing)
{
if (count == 1)
{
int count1;
for (count1 = 0; count1 < start_day; count1++)
{
cout << " " << endl;
prev_spacing++;
}
count_col =+ start_day;
}
else if (count != 1)
{
int spacing;
int count2;
int count_month = count;
nums_month (count_month, days_month, prev_day);
spacing = (prev_spacing + prev_day) % 7;
prev_spacing = 0;
for (count2 = 0; count2 < spacing; count2++)
{
cout << " ";
prev_spacing++;
count_col =+ spacing;
}
}
}
************************************************** **************
OUTPUT:
Which year of the calendar do you want?
2005
Which day do you want January 1st to start on?
Ex: Sunday = 0, Monday = 1, Tuesday = 2, etc
1
January
S M TU W TH F S
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
February
S M TU W TH F S
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
March
S M TU W TH F S
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
April
S M TU W TH F S
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
May
S M TU W TH F S
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
June
S M TU W TH F S
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
July
S M TU W TH F S
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
August
S M TU W TH F S
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
September
S M TU W TH F S
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
October
S M TU W TH F S
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
November
S M TU W TH F S
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
December
S M TU W TH F S
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
Press any key to continue . . .