• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

C++ using "IF's

GavinVG

New Member
Joined
Apr 14, 2010
Messages
13 (0.00/day)
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

New Member
Joined
Sep 23, 2008
Messages
67 (0.01/day)
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;
}
 
Last edited:
Joined
Aug 10, 2007
Messages
4,267 (0.70/day)
Location
Sanford, FL, USA
Processor Intel i5-6600
Motherboard ASRock H170M-ITX
Cooling Cooler Master Geminii S524
Memory G.Skill DDR4-2133 16GB (8GB x 2)
Video Card(s) Gigabyte R9-380X 4GB
Storage Samsung 950 EVO 250GB (mSATA)
Display(s) LG 29UM69G-B 2560x1080 IPS
Case Lian Li PC-Q25
Audio Device(s) Realtek ALC892
Power Supply Seasonic SS-460FL2
Mouse Logitech G700s
Keyboard Logitech G110
Software Windows 10 Pro
Seems like a working method for 1900 to 2099.

PHP:
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";
}
Code:
...
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
 
Top