Help with generating a calendar

Problem:
Write a program to generate a calendar for a year. The program should accept the year and the day of the week for January 1 of that year (0 = Sunday, 1 = Monday, etc.). The calendar should be printed in the following form:

January
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
1 2 3 4 5

I have wrote code that has three functions, one to print the month, one to print the days in month, and one to find if it is a leap year or not. I have gotten up to the point where I can print the 12 months with a for loop, but I have no idea how to print out the days in the format above. Can anyone help?

This is my code(sorry for any confusion I just started a couple months ago).

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <iostream>
using namespace std;

void printOneMonth(int month, int& dow, int year);
void daysInMonth(int month, int year, int& dim);
bool isLeapYear(int year);

int main(){
	int year=0, dow, count;
	cout << "Please enter the year: " << endl;
	cin >> year;
	cout << "Please enter the day of the week for January 1st: " << endl;
	cin >> dow;
	for(count=1; count<=12; count++){
		printOneMonth(count, dow, year);
		cout << endl;
	}


	return 0;
}

void printOneMonth(int month, int& dow, int year){
	switch(month)
	{
		case 1: cout << "January";
			break;
		case 2: cout << "Februrary";
			break;
		case 3: cout << "March";
			break;
		case 4: cout << "April";
			break;
		case 5: cout << "May";
			break;
		case 6: cout << "June";
			break;
		case 7: cout << "July";
			break;
		case 8: cout << "August";
			break;
		case 9: cout << "September";
			break;
		case 10: cout << "October";
			break;
		case 11: cout << "November";
			break;
		case 12: cout << "December";
			break;
	}
}


void daysinMonth(int month, int year, int& dim){	
	switch(month)
	{
	case 1: 
		dim=31;
		break;
	case 2: 
		if(isLeapYear(year))
		{
			dim=29;
		}
		else if(!isLeapYear(year))
		{
			dim=28;
		}
		break;
	case 3: 
		dim=31;
		break;
	case 4:
		dim=30;
		break;
	case 5:
		dim=31;
		break;
	case 6:
		dim=30;
		break;
	case 7:
		dim=31;
		break;
	case 8:
		dim=31;
		break;
	case 9:
		dim=30;
		break;
	case 10:
		dim=31;
		break;
	case 11:
		dim=30;
		break;
	case 12:
		dim=31;
		break;
	}

}	
	

bool isLeapYear(int year){
	if (year % 400 == 0 || year%100 != 0 && year%4 == 0) 
	{
		return true;
	}
	else
	{
		return false ; 
	}
}
You'll also need to know the day of the week that the first falls on for each month.

http://www.faqs.org/faqs/calendars/faq/part1/index.html
See 2.6 for the algorithm.

By the way, the days in a month follow a pretty simple pattern:

if month is February: days is (28 + is it a leap year?)
else if month < August: days is 30 + is month odd?
else: days is 31 - is month odd?

Good luck!
Topic archived. No new replies allowed.