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.