Year,Month,Day...? Anyone?

How's it going guys, I need a little help on this code I am working on for the extra credit problem on my homework. It says to write a C++ program to allow users to enter an integer y (year)from the key board, calculate n and p by using the following algorithms, and display n as month and p+1 as day on the screen. I am not sure I understand what the program is supposed to do. When I read it, it sounds like it wants you to type in a year and then its supposed to bring up a month and a day? That does not make too much sense to me seeing as there is 12 months in a year and 30+ days in any month. I do not see how typing in a year will select one month and day. The instructions then say

Divide y by 19 and call the remainder a. Ignore the quotient.
Divide y by 100 and get the quotient b and a remainder c.
Divide b by 4 and get a quotient d and a remainder e.
Divide b + 8 by 25 and get a quotient f. Ignore the remainder.
Divide b-f+1 by 3 and get a quotient g. Ignore the remainder.
Divide 19 * a + b - d - g + 15 by 30 and get remainder h. Ignore the quotient.
Divide c by 4 and get quotient I and remainder k.
Divide 32 + 2 * e + 2 * i - h - k by 7 and get a remainder r. Ignore quotient.
Divide a + 11 * h + 22 * r by 451 and get a quotient m. Ignore the remainder
Divide h + r - 7 * m + 114 by 31 and get a quotient n and a remainder p.

The code I compiled was

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  #include <iostream>
#include <math.h>

using namespace std;

int main ()
{
	int year;

	cout << "Please Enter a Year" << " \n " ;
	cin >> 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 r = (32+2*e+2*i-h-k/7);
	int m = (a+11*h+22*r%451);
	int n= (h+r-7*m+114%31);
	int p= (h+r-7*m+114/31);

	

	cout << " Month is " << n << " \n ";
	cout << " Day is " << p+1 << " \n"; 


	system ("pause");
	return 0;
}


When I run the code I receive negative numbers. I am lost on what I am supposed to receive and this is also only the second time I have used a compiler for the second homework. Sorry if this is really simple. I have never looked into or played with a programing compiler before this course.

You have your quotients and remainders wrong. Line 13 computes the quotient, not the remainder. Line 14 computes the remainder, not the quotient.

x/y gives the quotient. x%y gives the remainder.

I think the program computes the month/day of Easter.
Last edited on
Okay sorry about that, I switched all my incorrect signs and ended up with this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <math.h>

using namespace std;

int main ()
{
	int year;

	cout << "Please Enter a Year" << " \n " ;
	cin >> 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 r = (32+2*e+2*i-h-k%7);
	int m = (a+11*h+22*r/451);
	int n= (h+r-7*m+114/31);
	int p= (h+r-7*m+114%31);

	

	cout << " Month is " << n << " \n ";
	cout << " Day is " << p+1 << " \n"; 


	system ("pause");
	return 0;
}


However when I run the program I still get just negative numbers. Im not understanding what the program is supposed to give me back. For example when I run it and input the year 2002 in return I get the number -12525 for the month and -12506 for the day. What is the program supposed to give me?
On line 18, the compiler interprets b+8/25 as b+(8/25), not (b+8)/25. Multiplication/division have higher precedence than addition/subtraction. You have the same problem is several other places.

The program will print out the month and day number of Easter for the year that you give it.
Alright thank you for the help I finally got the code working correctly. The code is for a Anonymous Gregorian algorithm to find the month and day of Easter for the year that you input. I was missing the parentheses in all of my lines which caused the system to bug out. To get the remainder you use the percent sign % to get the quotient you use the division sign /. I had it correct on the first code I was using but the lack of parentheses was messing up the code. I added parentheses and switched back all the signs and ended up with a working code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <math.h>
using namespace std; 

int main ()
{
	int year;

	cout << "Please enter the year you want the date of Easter for " << " \n " ;
	cin >> 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 r = ((32+2*e+2*i-h-k)%(7));
	int m = ((a+11*h+22*r)/(451));
	int n= ((h+r-7*m+114)/(31));
	int p= ((h+r-7*m+114)%(31));

	cout << " The number of the month easter is/was on is " << n << " \n ";
	cout << " The number of the day easter is/was on is " << p+1 << " \n"; 


	system ("pause");
	return 0;
}


Thank you so much for the help and I hope to learn plenty more off of this site.
Topic archived. No new replies allowed.