| | |
Easter Sunday
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
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.
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
C++ Syntax (Toggle Plain Text)
#include "stdafx.h" #include <iostream> #include <string> #include <cmath> using namespace std; int main() { int x;//The year for which it is desired to compute Easter Sunday. 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<< "Enter the year you wish to inquire about"<<endl; cout<<x<<endl; cin>> x;//The 4-digit year. cout<< sun<<endl; return 0;
Last edited by Ancient Dragon; Jun 20th, 2007 at 8:50 pm. Reason: add code tags
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
#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?
#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?
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: C++ help
- Next Thread: Error messages aplenty!!!!!
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






