Need help with a calendar project

In this project a user needs to enter a numeric month and a year.
The output is a single calendar month with the name of the month followed by a grid of the days. My issue is that my day alignment is off. for example: if you enter the month of dec (12) and this year 2014 it says the month started on a wed when in fact it started on a monday. I am not sure if its my leap year calc or what. Please help?

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

#include<iostream>
using namespace std;

#define TRUE    1		// Used for Leapyear function
#define FALSE   0		// Used for Leapyear function

char *months[] =		//Month names for calendar
{
	" ",
	"\nJanuary",
	"\nFebruary",
	"\nMarch",
	"\nApril",
	"\nMay",
	"\nJune",
	"\nJuly",
	"\nAugust",
	"\nSeptember",
	"\nOctober",
	"\nNovember",
	"\nDecember"
};

int days_in_month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };	//Used to list #of days in month

int determinedaycode(int year)	//Function to determine day of the week
{
	int daycode;
	int d1, d2, d3;

	d1 = (year - 1.) / 4.0;
	d2 = (year - 1.) / 100.;
	d3 = (year - 1.) / 400.;
	daycode = (year + d1 - d2 + d3) % 7;
	return daycode;
}

int leapyear(int year)	//Function for determining if year is a leapyear or not
{
	if (year % 4 == FALSE && year % 100 != FALSE || year % 400 == FALSE)
	{
		days_in_month[2] = 29;
		return TRUE;
	}
	else {
		days_in_month[2] = 28;
		return FALSE;
	}
}

void calendar(int month, int year, int daycode)		//Function to display the Month
{
	int day, bar;


	printf("%s", months[month], year);
	cout << "\n\nSun  Mon  Tue  Wed  Thu  Fri  Sat" << endl;
	for (bar = 1; bar <= 33; bar++)					//Display '=" bar under days of the week
	{
		cout << '=';
	}
	cout << endl;
	
	for (day = 1; day <= 1 + daycode * 5; day++)	// Correct the postion for the first date
	{
		printf(" ");
	}

	for (day = 1; day <= days_in_month[month]; day++)
	{
		printf("%2d", day);

		if ((day + daycode) % 7 > 0)
			printf("   ");
		else
			printf("\n ");
	}
}
int main(void)		//Main input function
{
	int year;
	int month;
	int daycode;

	do
		{
			cout << "Enter a numeric month (1 - 12): " << endl;
			cin >> month;
		}

	while (month < 1 || month > 12);		//Constrains #'s to be 1-12
	
	do
		{
			cout << "Enter a year after 1582: " << endl;
			cin >> year;
		} 
	while (year < 1582);		//Allows for multiple try's to enter right year
		
		
	daycode = determinedaycode(year);
	leapyear(year);
	calendar(month, year, daycode);
	printf("\n");
		
		

	return 0;
}
Topic archived. No new replies allowed.