Calendar

So I had this assignment due a few weeks ago and couldn't figure out how to get what the professor wanted. He wants a calendar to generate for the the given year and taking into consideration leap years. But this calendar is supposed to generate and only print out specific months he wants it to print out (such as input is 1,3,5){prints January, March, and May and only those months}. For instance if you run this and input the year 2000 and say January starts on 1 which is Sunday. It should just print out those 3 months exactly how they appear in the set of 12 that prints out. This is my first post not really sure if I explained this well enough but just let me know because I'm stumped on this.


#include<iostream>
#include<cmath>
using namespace std;

int main ()
{
int year, start_day, type, n_days, month(1);
cout << "Enter the year you want the program to display. ";
cin >> year;
if ((year%400==0) || ((year%100==0) ^ (year%4==0)))
{
type = 1;
cout << "\nThe year is leap year.";
}
else
{
type = 0;
cout << "\nThe year is odd year.";
}
cout << "\nEnter the first day of January: 1 for Sunday, 2 for Monday, etc. ";
cin >> start_day;
while (start_day <= 0 || start_day > 7)
{
cout << "\nThe number entered is invalid.\nPlease enter a number between 1 and 7. ";
cin >> start_day;
}

while (month <= 12)
{

switch (month)
{
case 1:
cout << "\n\nJanuary\n" << endl;
n_days = 31;
break;
case 2:
cout << "\n\nFebruary\n" << endl;
if (type == 1)
{
n_days = 29;
}
else
{
n_days = 28;
}
break;
case 3:
cout << "\n\nMarch\n" << endl;
n_days = 31;
break;
case 4:
cout << "\n\nApril\n" << endl;
n_days = 30;
break;
case 5:
cout << "\n\nMay\n" << endl;
n_days = 31;
break;
case 6:
cout << "\n\nJune\n" << endl;
n_days = 30;
break;
case 7:
cout << "\n\nJuly\n" << endl;
n_days = 31;
break;
case 8:
cout << "\n\nAugust\n" << endl;
n_days = 31;
break;
case 9:
cout << "\n\nSeptember\n" << endl;
n_days = 30;
break;
case 10:
cout << "\n\nOctober" << endl;
n_days = 31;
break;
case 11:
cout << "\n\nNovember" << endl;
n_days = 30;
break;
case 12:
cout << "\n\nDecember\n" << endl;
n_days = 31;
break;
default:
;
}

cout << endl << "Sun\tMon\tTue\tWed\tThr\tFri\tSat\n";
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1)% 7 == 0)
{

cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month ++;

}


return 0;
}
So you make a calendar just like normal, but before you print the requested month, you check to see if it's one of the requested.
So can I still use the case statement to run the list and have it set for (months)? or am I going to have to change it to an series of if-statements?
Edit : Also can I have the userInput for months store more than one value? such as 1,3,5 or is that impossible?
Last edited on
As far as i can tell your only getting one value from the user.

cin >> year;

Depending on how you fix that, may determine how you manage to print the requested month.
So me just adding a cin >> months wouldn't resolve because its only going to do whatever value is first stored entered. So there isn't a way a variable could store 1,3,5? Am I just taking the wrong approach at this and should I try to do it another way? I feel like its close its just missing like literally one step haha
@Whaves

Getting it to print only the months requested, was easy enough. The problem you're going to have, is printing the days of the months in their correct positions.
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
115
116
117
118
119
120
121
122
123
124
125
126
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	int year, start_day, type, n_days, month(1), display[13] = { 0 };
	int x;
	cout << "Enter the year you want the program to display. ";
	cin >> year;
	if ((year % 400 == 0) || ((year % 100 == 0) ^ (year % 4 == 0)))
	{
		type = 1;
		cout << "\nThe year is leap year.";
	}
	else
	{
		type = 0;
		cout << "\nThe year is odd year.";
	}
	cout << "\nEnter the first day of January: 1 for Sunday, 2 for Monday, etc. ";
	cin >> start_day;
	while (start_day <= 0 || start_day > 7)
	{
		cout << "\nThe number entered is invalid.\nPlease enter a number between 1 and 7. ";
		cin >> start_day;
	}
	do
	{
		cout << "Display which months [1 to 12]. Enter a 0 to end choosing.." << endl;
		cin >> x;
		if (x != 0)
			display[x] = 1;
	} while (x != 0);
	for (x = 1; x < 13; x++)
	{

		if (display[x])\\ If this month was selected
		{
			switch (x) 
			{
			case 1:
				cout << "\n\nJanuary\n" << endl;
				n_days = 31;
				break;
			case 2:
				cout << "\n\nFebruary\n" << endl;
				if (type == 1)
				{
					n_days = 29;
				}
				else
				{
					n_days = 28;
				}
				break;
			case 3:
				cout << "\n\nMarch\n" << endl;
				n_days = 31;
				break;
			case 4:
				cout << "\n\nApril\n" << endl;
				n_days = 30;
				break;
			case 5:
				cout << "\n\nMay\n" << endl;
				n_days = 31;
				break;
			case 6:
				cout << "\n\nJune\n" << endl;
				n_days = 30;
				break;
			case 7:
				cout << "\n\nJuly\n" << endl;
				n_days = 31;
				break;
			case 8:
				cout << "\n\nAugust\n" << endl;
				n_days = 31;
				break;
			case 9:
				cout << "\n\nSeptember\n" << endl;
				n_days = 30;
				break;
			case 10:
				cout << "\n\nOctober" << endl;
				n_days = 31;
				break;
			case 11:
				cout << "\n\nNovember" << endl;
				n_days = 30;
				break;
			case 12:
				cout << "\n\nDecember\n" << endl;
				n_days = 31;
				break;
			default:
				;
			}

			cout << endl << "Sun\tMon\tTue\tWed\tThr\tFri\tSat\n";
			for (int i = 1; i < start_day; i++)
			{
				cout << " \t";
			}
			for (int j = 1; j <= n_days; j++)
			{

				if ((j + start_day - 1) % 7 == 0)
				{
					cout << j << "\t";
					cout << endl;
				}
				else
					cout << j << "\t";
			}
			cout << endl << endl;
			start_day = ((start_day + n_days) % 7);
			month++;

		}
	}


	return 0;
}
Last edited on
Okay so I broke down that. Not really sure how that incrementer works (i'm guessing its an array based on the []) but it works nice. So instead of that for-loop checking to see if the number was selected I think it needs to run the whole case statement. Within the case statement its going to need an if-else statement for all of them. If the number is selected it needs to print dates for the month. If not it needs to have a blank run anyways but hold and pretend that it ran (no idea if that makes sense haha) then if the number is asked to print out again later in the case it can take the previous held numbers and pick back off where it should start at.
@Whaves

Here is something that may help. It's a program I converted from BASIC to C++. The program lets you know what day of the week a day falls on in a given month, day and year. Hopefully, you can use the idea in your program to display the given months.
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Zeller Congruence.cpp : main project file.

#include <iostream>
#include <string>
#include <Windows.h>

using std::cout;
using std::cin;
using std::endl;
using std::string;

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);

void Sort_Date(string Date, int &month, int &day, int &year);
bool ck_date(int month, int day, int year, int days[12], string Month[12]);
int Zeller_Congruence(int month, int day, int year);
char WaitKey();

int main()
{
	int month = 0, day = 0, year = 0, Date_falls_on;
	bool ok = false;
	string Date;
	cout << "This program will ask for a specific date, and then," << endl << "will let you know what day it fell on." << endl << endl << endl;
	string Month[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
	string Day_of_week[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
	int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	do
	{
		do
		{
			cout << endl << "Enter the date as 'MM/DD/YYYY' or 'MM-DD-YYYY'" << endl << "Enter a '0', to end program." << endl << endl;
			cin >> Date;
			
			if (Date != "0")
			{
				if (((Date[2] == '/' && Date[5] == '/') || (Date[2] == '-' && Date[5] == '-')) && Date.length() == 10)
				{
					Sort_Date(Date, month, day, year);
					if (year < 1582)
						cout << "This program only works correctly when using the Gregorian Calendar" << endl << " which was started in 1582. Please enter a different date.." << endl << endl;
					ok = ck_date(month, day, year, days, Month);
				}
				else
					cout << "Your date format, is not correct. Please re-enter a date.." << endl << endl;
			}
			else
			  ok = true;
		} while (!ok);

		if (Date != "0")
		{
			Date_falls_on = Zeller_Congruence(month, day, year);

			cout << endl << endl << Month[month - 1] << " " << day << ", " << year << ", falls on a " << Day_of_week[Date_falls_on] << ", in a ";
			bool A_Leap_Year = ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0));
			if (!A_Leap_Year)
				cout << "non-";
			cout << "leap year!" << endl << endl;
		}
	} while (Date != "0");

	cout << "\t\tThe program is now closed. Bye..." << endl;
	WaitKey();
	return 0;
}

void Sort_Date(string Date, int &month, int &day, int &year)
{
	month = ((Date[0]) - 48) * 10;
	month += Date[1] - 48;

	day = ((Date[3]) - 48) * 10;
	day += Date[4] - 48;

	year = ((Date[6]) - 48) * 1000;
	year += ((Date[7]) - 48) * 100;
	year += ((Date[8]) - 48) * 10;
	year += Date[9] - 48;
}

bool ck_date(int month, int day, int year, int days[12], string Month[12])
{
	bool ck = true;

	bool A_Leap_Year = ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0));
	if (A_Leap_Year)
		days[1] = 29;

	if (year < 1582)
		ck = false;

	if (month < 1 || month >12)
	{
		ck = false;
		if (month < 1)
			cout << "You have to give me something I can work with. Try again.." << endl << endl;
		if (month>12)
			cout << "Don't know where you're from, but we only have 12 months.." << endl << "Please try again." << endl << endl;
	}

	if (ck && ( day < 1 || day > days[month - 1]))
	{
		ck = false;
		if (day < 1)
			cout << "You have to give me something I can work with. Try again.." << endl << endl;
		if (day > days[month - 1])
			cout << "Sorry to inform you, but there are only " << days[month - 1] << " days in " << Month[month - 1] << ".. " << endl << "Please try again." << endl << endl;
	}

	return ck;
}

int Zeller_Congruence(int month, int day, int year)
{
	int week_day;
	if (month < 3)
	{
		year--;
		month += 12;
	}
	week_day = (((13 * month + 3) / 5 + day + year + year / 4 - year / 100 + year / 400 + 1) % 7);

	return week_day;
}

char WaitKey()
{
	HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
	INPUT_RECORD irInputRecord;
	DWORD dwEventsRead;
	CHAR cChar;
	cout << endl << endl << "\tPress 'ENTER', to close this program." << endl << endl;
	while (ReadConsoleInputA(hStdin, &irInputRecord, 1, &dwEventsRead)) /* Read key press */
		if (irInputRecord.EventType == KEY_EVENT
			&&irInputRecord.Event.KeyEvent.wVirtualKeyCode != VK_SHIFT
			&&irInputRecord.Event.KeyEvent.wVirtualKeyCode != VK_MENU
			&&irInputRecord.Event.KeyEvent.wVirtualKeyCode != VK_CONTROL)
		{
			cChar = irInputRecord.Event.KeyEvent.uChar.AsciiChar;
			ReadConsoleInputA(hStdin, &irInputRecord, 1, &dwEventsRead); /* Read key release */
			return cChar;
		}
	return EOF;
}
not really what is going on exactly with that code at the end :/ only it that CS1 haha . I was trying to fiddle with it more and think the array could work but it needs to check it within the statement. I do it for months 1,2,3, but on 4 I try to make a else statement that just adds up the days and hopefully carrys it over to the next month but I am not sure how to make an if-else statement for arrays


//
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
int year, start_day, type, n_days, month(1), display[13] = { 0 };
int x;
cout << "Enter the year you want the program to display. ";
cin >> year;
if ((year % 400 == 0) || ((year % 100 == 0) ^ (year % 4 == 0)))
{
type = 1;
cout << "\nThe year is leap year.";
}
else
{
type = 0;
cout << "\nThe year is odd year.";
}
cout << "\nEnter the first day of January: 1 for Sunday, 2 for Monday, etc. ";
cin >> start_day;
while (start_day <= 0 || start_day > 7)
{
cout << "\nThe number entered is invalid.\nPlease enter a number between 1 and 7. ";
cin >> start_day;
}
do
{
cout << "Display which months [1 to 12]. Enter a 0 to end choosing.." << endl;
cin >> x;
if (x != 0)
display[x] = 1;
} while (x != 0);
for (x = 1; x < 13; x++)
{

if (display[x])
{
switch (x)
{
case 1:
cout << "\n\nJanuary\n" << endl;
n_days = 31;
cout << endl << "Sun\tMon\tTue\tWed\tThr\tFri\tSat\n";
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
break;
case 2:
cout << "\n\nFebruary\n" << endl;
if (type == 1)
{
n_days = 29;
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
}
else
{
n_days = 28;
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
}
break;
case 3:
cout << "\n\nMarch\n" << endl;
n_days = 31;
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
break;
case 4:
cout << "\n\nApril\n" << endl;
n_days = 30;
if (display[x])
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
else
start_day += 30;
break;
case 5:
cout << "\n\nMay\n" << endl;
n_days = 31;
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
break;
case 6:
cout << "\n\nJune\n" << endl;
n_days = 30;
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
break;
case 7:
cout << "\n\nJuly\n" << endl;
n_days = 31;
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
break;
case 8:
cout << "\n\nAugust\n" << endl;
n_days = 31;
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
break;
case 9:
cout << "\n\nSeptember\n" << endl;
n_days = 30;
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
break;
case 10:
cout << "\n\nOctober" << endl;
n_days = 31;
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
break;
case 11:
cout << "\n\nNovember" << endl;
n_days = 30;
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
break;
case 12:
cout << "\n\nDecember\n" << endl;
n_days = 31;
{
for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{

if ((j + start_day - 1) % 7 == 0)
{
cout << j << "\t";
cout << endl;
}
else
cout << j << "\t";
}
cout << endl << endl;
start_day = ((start_day + n_days) % 7);
month++;
}
break;
default:
;
}

}
}


return 0;
}
@Whaves

The main part of the program, I wanted you to use, was the function called Zeller_Congruence.

Here's the program, that displays only the months entered, with the first in the correct starting position.
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include<iostream>
#include <string>
//#include<cmath> // not needed
#include <Windows.h>

using std::cout;
using std::cin;
using std::endl;
using std::string;

int Zeller_Congruence(int month, int day, int year);
char WaitKey();

int main()
{
	int year, start_day, type=0, n_days, month(1), display[13] = { 0 };
	int x;

	cout << "Enter the year you want the program to display. ";
	cin >> year;
	if ((year % 400 == 0) || ((year % 100 == 0) ^ (year % 4 == 0)))
	{
		type = 1;
		cout << "\nThe year is leap year.";
	}
	else
		cout << "\nThe year is not a leap year.";
		
	do
	{
		cout << endl << "Display which months [1 to 12]. Enter a 0 to end choosing.." << endl;
		cin >> x;
		if (x != 0)
			display[x] = 1;
	} while (x != 0);
	for (x = 1; x < 13; x++)
	{

		if (display[x]) // If display[x] is 1
		{
			switch (x) // switch to value of x from for loop
			{
			case 1:
				cout << endl << "\t\t\tJanuary" << endl; // Use three tab commands to center month name over calendar
				n_days = 31;
				break;
			case 2:
				cout << endl << "\t\t\tFebruary" << endl;
				  n_days=28; // Days in February is 28
				if (type == 1) // If a Leap Year
					n_days = 29; // Days in February now 29
				break;
			case 3:
				cout << endl << "\t\t\tMarch" << endl;
				n_days = 31;
				break;
			case 4:
				cout << endl << "\t\t\tApril" << endl;
				n_days = 30;
				break;
			case 5:
				cout << endl << "\t\t\tMay" << endl;
				n_days = 31;
				break;
			case 6:
				cout << endl << "\t\t\tJune" << endl;
				n_days = 30;
				break;
			case 7:
				cout << endl << "\t\t\tJuly" << endl;
				n_days = 31;
				break;
			case 8:
				cout << endl << "\t\t\tAugust" << endl;
				n_days = 31;
				break;
			case 9:
				cout << endl << "\t\t\tSeptember" << endl;
				n_days = 30;
				break;
			case 10:
				cout << endl << "\t\t\tOctober" << endl;
				n_days = 31;
				break;
			case 11:
				cout << endl << "\t\t\tNovember" << endl;
				n_days = 30;
				break;
			case 12:
				cout << endl << "\t\t\tDecember" << endl;
				n_days = 31;
				break;
			}
			if (display[x])
			{
				start_day = Zeller_Congruence(x, 1, year);// Find which day the 1st is on
				cout << "Sun\tMon\tTue\tWed\tThu\tFri\tSat" << endl;
				for (int i = 0; i < start_day; i++)
				{
					cout << " \t";
				}
				for (int j = 1; j <= n_days; j++)
				{
					if (j < 10)
						cout << " ";
					cout << j << "\t";
					if ((j + (start_day)) % 7 == 0)
						cout << endl;
				}
			}
			cout << endl;
		}
	}
	cout << endl << endl;
	WaitKey(); // Waiting for a keypress, to close program
	return 0;
}

int Zeller_Congruence(int month, int day, int year)
{
	if ((month) < 3)
	{
		year--;
		month += 12;
	}
	int week_day = (((13 * month + 3) / 5 + day + year + year / 4 - year / 100 + year / 400 + 1) % 7);
	return week_day;
}

char WaitKey() // Just to wait for keyboard input. Do not use System("Pause"); 
{
	HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
	INPUT_RECORD irInputRecord;
	DWORD dwEventsRead;
	CHAR cChar;
	cout << endl << endl << "\tPress 'ENTER', to close this program." << endl << endl;
	while (ReadConsoleInputA(hStdin, &irInputRecord, 1, &dwEventsRead)) /* Read key press */
		if (irInputRecord.EventType == KEY_EVENT
			&&irInputRecord.Event.KeyEvent.wVirtualKeyCode != VK_SHIFT
			&&irInputRecord.Event.KeyEvent.wVirtualKeyCode != VK_MENU
			&&irInputRecord.Event.KeyEvent.wVirtualKeyCode != VK_CONTROL)
		{
			cChar = irInputRecord.Event.KeyEvent.uChar.AsciiChar;
			ReadConsoleInputA(hStdin, &irInputRecord, 1, &dwEventsRead); /* Read key release */
			return cChar;
		}
	return EOF;
}
So I have been looking at places to put Zeller at but I'm not sure where Zeller Congruence is effective at in my code? Do I need to rework this in my for loop? Sorry I know that is a function but I'm not really familiar with those yet we literally just learned that last week.
@Whaves

Like I show on line 96
start_day = Zeller_Congruence(x, 1, year);// Find which day the 1st is on
start_day will be the value of the return. You're sending the function, 3 pieces of information. The number of the month, as int x, the value 1, for the 1st day of the month and lastly, the year. The function, Zeller_Congruence, will return what day in the week, that day falls on.
Then the loop starting at line 98, will put a space for each number less than start_day. And then the calendar month gets printed. This will happen for each of the months you specified, and in the order they appear in a real calendar. Meaning, if you enter 2, 7, 4, for the months to be viewed, the calendar program will print out 2, 4 and then 7.

The WaitKey function could be removed, if you want. Just use cin >> x; at line 115 to pause the screen so it doesn't close immediately after printing the calendar months.
Last edited on
Topic archived. No new replies allowed.