Alright so my task was to make a program in C++ that when entering a year would output the date easter landed on and this is what we were given

a=year MOD 19
b=year/100
c=year MOD 100
d=b/4
e=b MOD 4
f=(b+8)/25
g=(b-f+1)/3
h=(19a+b-d-g+15) MOD 30
i=c/4
k=c MOD 4
m=(32+2e+2i-h-k) MOD 7
n=(a+11h+22m)/451
Easter Month = (h+m-7n+114)/31 [3=March, 4=April]
Easter Day = 1+(h+m-7n+114) MOD 31

alright so thats the big ol' long equation we were given to find the date easter lands on for a given year, so the program i wrote is:

#include <iostream>

using namespace std;

int main()
{
int year;
int a = year % 19;
int b = year/100;
int c = year % 100;
int d = b/4;
int e = b % 4;
int f = (b+8)/25;
int g = (b-f+1)/3;
int h = (19*a+b-d-g+15) % 30;
int i = c/4;
int k = c % 4;
int m = (32+2*e+2*i-h-k) % 7;
int n = (a+11*h+22*m)/451;
int EasterMonth = (h+m-7*n+144)/31;
int EasterDay = 1+(h+m-7*n+144) % 31;
cout << "The following program will output the date of which easter fell on or will fall on for any given year inputted according to the Gregorian Calender" << endl;
cout << "Enter desired year:" << endl;
cin >> year;//The 4-digit year.
cout << "Easter in the year " << year << " will fall on " << endl;
if (EasterMonth=3)
cout << "March ";
else
cout << "April ";
cout << EasterDay << endl;
    return 0;
}

Now everytime i enter a date no matter what the outcome i receive is March8. I was wondering if anyone could help me in showing me where my error is

Please use the code tagging by tabulating your code one more level by hightlight and TAB, before the 30 min editing window finishes!

alright sorry about that

alright i added the {} brackets and changed the = sign to a == sign in he code

if (EasterMonth=3)

fixing some problems, also noticed i had an error in

int EasterDay = 1+(h+m-7*n+144) % 31;

should have been a 114 not 144

now i keep getting an answer of April 9 though so it seems my main error is still present, no matter what i enter i yeild the same date

i added a cout << b << endl; to the end of it and entered 2012 and found that it output a 0. im a litle confused wh it would do this when b is defined as the year/100, thinking maybe this is a part of the problem??

Take a closer look at your code. The problem is occurring because you need to input the year before doing any of your calculations.
As your code stands, the value of EasterDay is being calculated before the user has even input the year.
So the uninitialised year variable is used in your calculations!

took a while but i found it out answering my own question lol but thanks

#include <iostream>

using namespace std;

int main()
{
cout << "The following program will output the date of which easter fell on or will fall on for any given year inputted according to the Gregorian Calender" << endl;
cout << "Enter desired year:" << endl;
int year, a, b, c, d, e, f, g, h, i, k, m, n, EasterMonth, EasterDay;
cin >> year;
 a = year % 19;
 b = year/100;
 c = year % 100;
 d = b/4;
 e = b % 4;
 f = (b+8)/25;
 g = (b-f+1)/3;
 h = (19*a+b-d-g+15) % 30;
 i = c/4;
 k = c % 4;
 m = (32+2*e+2*i-h-k) % 7;
 n = (a+11*h+22*m)/451;
 EasterMonth = (h+m-7*n+114)/31;
 EasterDay = 1+(h+m-7*n+114) % 31;
cout << "Easter in the year " << year << " will fall on " << endl;
if (EasterMonth==3){
    cout << "March ";
}else{
    cout << "April ";}
cout << EasterDay << endl;
    return 0;
}

had to put cin >> year; above all the equations for a, b, c ,etc. but int year. was giving me some garbage numbers that were already in the computer becuase i was not using my actual input year, thanks for the help still.

You have missing braces.

You have missing braces.

No, he have all the brackets needed at the previous code posted
if your referring to the else condition's bracket then it's found at the end on line 29

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.