Easter Calculator Loop help?

The instructions are:
Write a program that inputs a beginning year and an ending year and outputs a chart of Easter Sundays.

I have the forumla down, I'm just having trouble because it's only printing out one result, it's suppose to print out the calculations for all the easter sunday between the two years, but this one only prints the first number you enter. Anyway I can make it loop and show the results of all the sunday's inbetween? Thanks a million in advance all help is welcomed


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
#include <iostream>
#include <iomanip>
using namespace std;
int main () 

{
	int a, b, c, d, e;
	int day, year, yearend;
	int scount, ecount;
	
	a = year % 19;
	b = year % 4;
	c = year % 7;
	d = (19 * a + 24) % 30;
	e = (2 * b + 4 * c + 6 * d + 5) % 7;
	day = 22 + d + e;
	scount = year;
	ecount = yearend;
	
cout << "This program will show you which day Easter Sunday will " << endl;
cout << "fall on from any year between 1900 to 2099." << endl << endl;
cout << "Press <enter> after each piece of input data!" << endl << endl;
cout << "Please input the beginning year for the chart (1900-2099)? " << endl;
cin >> year;
cout << "Please input the ending year for the chart (1900-2099)? ";
cin >> yearend;

if (year <1900 || year >2099 || yearend < year) 
	{ 
		cout << "Invalid information.....Program Terminated!" << endl;
	return 0; //terminate the program. 
	}
	
while(scount<ecount)
	{
	
if (day > 31) {
		cout << "April ";
		day = d + e - 9;
		if (year == 1954 || year == 1981 || year == 2049 || year == 2076) {
			day = d + e - 16; 
		}
	}
else {
		cout << "March ";
	}
	
	cout << day << ", " << year << endl;
	return 0;	
	}
	
if (day > 31) {
		cout << "April ";
		day = d + e - 9;
		if (year == 1954 || year == 1981 || year == 2049 || year == 2076) {
			day = d + e - 16; 
		}
	}
else {
		cout << "March ";
	}
 
	cout << "Easter Sunday is " << endl; 
	//this calculation formula works only for the certain range of 
	//year values.
	
	cout << day << ", " << year << endl;
return 0;
}
Last edited on
Lines 11 to 18 are at the wrong place. year and yearend are not initialized at that point. Move the lines after line 26.
Okay here's the changed code. I moved the lines but it still doesn't print out all the years inbetween.


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
#include <iostream>
#include <iomanip>
using namespace std;
int main () 

{
	int a, b, c, d, e;
	int day, year, yearend;
	int scount, ecount;
	
	
	b = year % 4;
	c = year % 7;
	d = (19 * a + 24) % 30;
	e = (2 * b + 4 * c + 6 * d + 5) % 7;
	day = 22 + d + e;

	
cout << "This program will show you which day Easter Sunday will " << endl;
cout << "fall on from any year between 1900 to 2099." << endl << endl;
cout << "Press <enter> after each piece of input data!" << endl << endl;
cout << "Please input the beginning year for the chart (1900-2099)? " << endl;
cin >> year;
cout << "Please input the ending year for the chart (1900-2099)? ";
cin >> yearend;

a = year % 19;
scount = year;
ecount = yearend;

if (year <1900 || year >2099 || yearend < year) 
	{ 
		cout << "Invalid information.....Program Terminated!" << endl;
	return 0; //terminate the program. 
	}
	
while(scount<ecount)
	{
	
if (day > 31) {
		cout << "April ";
		day = d + e - 9;
		if (year == 1954 || year == 1981 || year == 2049 || year == 2076) {
			day = d + e - 16; 
		}
	}
else {
		cout << "March ";
	}
	
	cout << day << ", " << year << endl;
	return 0;	
	}
	
if (day > 31) {
		cout << "April ";
		day = d + e - 9;
		if (year == 1954 || year == 1981 || year == 2049 || year == 2076) {
			day = d + e - 16; 
		}
	}
else {
		cout << "March ";
	}
 
	cout << "Easter Sunday is " << endl; 
	//this calculation formula works only for the certain range of 
	//year values.
	
	cout << day << ", " << year << endl;
return 0;
}
Last edited on
1
2
Line 14 error C4700: uninitialized local variable 'year' used	
Line 16 error C4700: uninitialized local variable 'a' used	


This will always be true since you don't change ecount.
while(scount<ecount)

I think it would be much easier if you write a function to calculate it and call this function in a for loop.
1
2
3
4
5
6
7
8
9
10
11
12
void CalcEaster (int year, int& day, string& month)
{
   // your calculation here
}
int day;
string month;
for (int i = year; i < yearend; i++)
{
   CalcEaster(i, day, month);
   // display date
}

Move all calculations depending on year or yearend after year / yearend finally have a valid value.

What do you think is the value of year on line 12? And what will be the result of the calculation?
Topic archived. No new replies allowed.