Easter Sunday

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2007
Posts: 2,462
Reputation: zandiago is on a distinguished road 
Solved Threads: 25
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Easter Sunday

 
0
  #1
Jun 20th, 2007
I need to write a C++ program that can be used to calculate the date of any Easter Sunday which can be computed as follows;

Let X be the year for which it is desired to compute Easter Sunday.
Let A be the remainder of the division of X by 19.
Let B be the remainder of the division of X by 4.
Let C be the remainder of the division of X by 7.
Let D be the remainder of the division of (19*A+24) by 30.
Let E be the remainder of the division of (2*B+4*C+6*D+5) by 7.

Easter Sunday = March 22+D+E. (Note-This can give a date in April)

The program should prompt the user for a year and then calculates and outputs (properly labeled), the correct month, day and year for that year’s Easter Sunday.

I'm understanding the subject a little bit. I think there it should include 'if' and 'else' statements.

See my code I have thus far: I get an error message that says that 'x' has not been assigned a value...But 'x' is what I want to personally enter as 'cin'- the year.

Thanks.
--------------------------------------------------------------------------------
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.  
  11. int x;//The year for which it is desired to compute Easter Sunday.
  12. int a = x % 19;//The remainder of the division of x by 19.
  13. int b = x % 4;//The remainder of the division of x by 4.
  14. int c = x % 7;//The remainder of the division of x by 7.
  15. int d = (19 * a) + (24) % 30;//The remainder of the division of (19*a + 24) by 30.
  16. int e = (2 * b) + (4 * c) + (6 * d) + (5) % 30;//The remainder of the division of (2*b+4*c+6*d+5) by 7.
  17. int sun = (22 + d + e);//The calculation of easter sunday.
  18. cout<< "Enter the year you wish to inquire about"<<endl;
  19. cout<<x<<endl;
  20. cin>> x;//The 4-digit year.
  21. cout<< sun<<endl;
  22. return 0;
Last edited by Ancient Dragon; Jun 20th, 2007 at 8:50 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Easter Sunday

 
0
  #2
Jun 20th, 2007
You are trying to output the value of x before actually getting the value. IE. You are using cout<<x<< endl; before cin>> x;
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2,462
Reputation: zandiago is on a distinguished road 
Solved Threads: 25
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: Easter Sunday

 
0
  #3
Jun 20th, 2007
Ok...thx for your help-now I see it. But where would and 'if' else statement be necessary in such a program? I'm in my first month of C++ and I'm struggling to catch on to it. I really appreaciate all the assistance. I had tried and example- i had inputted '1999'- and i got a result of '749'. I know it doesn't make any sense, but It's suppose to calculate and show the day, month and year. Thx.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,342
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Easter Sunday

 
0
  #4
Jun 20th, 2007
That error message means that when line line 12 is executed variable x has not been assigned a value yet so it just contains some random value. Programs are normally executed in the same order that you code them, so line 12 is executed immediately after line 11, and line 13 after line 12, etc.

To correct the error you received you need to move lines 18, 19 and 20 up between line 11 and 12 so that the value of x is entered at the keyboard before attemtping to execute lines 12 thru 16.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2,462
Reputation: zandiago is on a distinguished road 
Solved Threads: 25
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: Easter Sunday

 
0
  #5
Jun 21st, 2007
Ok...thx for your help-now I see it. But where would and 'if' else statement be necessary in such a program? I'm in my first month of C++ and I'm struggling to catch on to it. I really appreaciate all the assistance. I had tried and example- i had inputted '1999'- and i got a result of '749'. I know it doesn't make any sense, but It's suppose to calculate and show the day, month and year. Thx.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Easter Sunday

 
0
  #6
Jun 21st, 2007
Well firstly you are trying to do math with x before it actually has a variable so once it gets the others (a, b, c, d, e, sun) aren't actually giving the correct number
Last edited by ShawnCplus; Jun 21st, 2007 at 2:31 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2,462
Reputation: zandiago is on a distinguished road 
Solved Threads: 25
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: Easter Sunday

 
0
  #7
Jun 21st, 2007
You want to run that by me again? If i enter a value from the keyboard-doesn't a program automatically do the calculation? You kinna lost me there.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2,462
Reputation: zandiago is on a distinguished road 
Solved Threads: 25
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: Easter Sunday

 
0
  #8
Jun 21st, 2007
Also, where do the 'if' and 'else' statements come into play with such a program?
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Easter Sunday

 
0
  #9
Jun 21st, 2007
Originally Posted by zandiago View Post
You want to run that by me again? If i enter a value from the keyboard-doesn't a program automatically do the calculation? You kinna lost me there.
Yes it does but you are trying to do the calculations before you have gotten any input. It is trying to do the math on a number that doesn't exist.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2,462
Reputation: zandiago is on a distinguished road 
Solved Threads: 25
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: Easter Sunday

 
0
  #10
Jun 21st, 2007
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>

using namespace std;

int main()
{
cout<< "Enter the year you wish to inquire about";



int x;//The year for which it is desired to compute Easter Sunday.
cin>> x;//The 4-digit year.
int a = x % 19;//The remainder of the division of x by 19.
int b = x % 4;//The remainder of the division of x by 4.
int c = x % 7;//The remainder of the division of x by 7.
int d = (19 * a + 24) % 30;//The remainder of the division of (19*a + 24) by 30.
int e = (2 * b + 4 * c + 6 * d + 5) % 30;//The remainder of the division of (2*b+4*c+6*d+5) by 7.
int sun = (22 + d + e);//The calculation of easter sunday.
cout<<setw(4)<< "Day" <<setw(8)<< "Month" <<setw(8)<< "Year"<<endl;
cout<<setw(20)x<<endl;

return 0;
}
------------------------------------------------------------------------------
But doesn't my position of 'cin' allow for that value to be calculated? I was able to get the year...and how does this program require a 'if' and 'else' statements?
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC