# C++ using "IF's



## GavinVG (Sep 15, 2011)

So i have to write a program that does this:  Given the year inputted by the user, calculate the month and day of Easter Sunday. When the
program executes, it should produce output similar to this.

Easter Sunday Calculator
Enter the year: 1985
Easter Sunday is April 7, 1985

	The formula is a complex one and produces the correct day for any year from 1900
through 2099. I have broken it down into intermediate steps as follows. Frequently, Easter
Sunday is in March, but occasionally it is in April. The following formula calculates the day of
the month in March of Easter Sunday.
let a = year % 19
let b = year % 4
let c = year % 7
now start to put these pieces together
let d = (19 * a + 24) % 30
let e = (2 * b + 4 * c + 6 * d + 5) % 7
finally, the day of the month of Easter Sunday is
let day = 22 + d + e

However, if the day is greater than 31, then subtract 31 days from day and the resulting value in day is in April instead. But the equation is off by exactly 7 days if these years are used: 1954, 1981, 2049 and 2076. Thus, when the calculation is finished, if the year is one of these four, you must subtract 7 days from the day variable. The subtraction does not cause a change in the month.

*Well i dont know how to get past my Input stage. I basically dont know how to start it after that i will probably be able to finish other stages. I just need help on how the Process stage should start*


----------



## Jacko28 (Sep 15, 2011)

I'm new to programming myself but I'm sure you can use a do/while statement, just make the while something like;

// Very roughly done

#include <iostream>
using namespace std;
int main()
{

 do {

      (insert code)  
          {

            (more code)

          }

     } while (a==1954 || a==1981 || a==2049 || a==2076);


          return 0;
}


----------



## Disparia (Sep 15, 2011)

Seems like a working method for 1900 to 2099.


```
for ($y = 1900; $y <= 2099; ++$y) {
	$a = (19 * ($y % 19) + 24) % 30;
	$d = 22 + $a + ((2 * ($y % 4) + 4 * ($y % 7) + 6 * $a + 5) % 7);

	$m = 'March';
	if ( $d > 31 ) {
		$m = 'April';
		$d-= 31;
	}

	if ( $y == 1954 || $y == 1981 || $y == 2049 || $y == 2076 ) {
		$d-= 7;
	}

	echo $y, ': ', $m, ' ', $d, "\n";
}
```


```
...
2005: March 27
2006: April 16
2007: April 8
2008: March 23
2009: April 12
2010: April 4
2011: April 24
2012: April 8
2013: March 31
2014: April 20
2015: April 5
...
```

On the topic of Easter calculation, this one claims to work for 326 to 4099:

http://www.assa.org.au/edm.html


----------

