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
#include <iostream>
#include <iomanip>
usingnamespace 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;
}
#include <iostream>
#include <iomanip>
usingnamespace 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;
}
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
}