### Zeller's Congruence

I am getting some weird results like 2513 instead of 0-6 result. I've reviewed over and cant find anything wrong, could someone help?

 ``12345678910111213141516171819202122`` ``````#include #include using namespace std; int main() { int year, month, day, h; cout << "Enter a year from the Gregorian Calendar: "; cin >> year; cout << "Enter a month from the Gregorian Calendar: "; cin >> month; cout << "Enter a day from the Gregorian Calendar: "; cin >> day; h = (day + (13 * (month + 1) / 5) + (year) + (year / 4) - (year / 100) + (year / 400) % 7); cout << h << endl; return 0; }``````
Last edited on
Line 17 ends with `) % 7);`, but I think you probably meant `)) % 7;`.
Thank you I am trying the solution right now.
Last edited on
Thank you very much the code works perfectly now and I did some refinements to it.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455`` ``````#include #include using namespace std; int main() { int year, month, day, h; cout << "Enter a year from the Gregorian Calendar: "; cin >> year; cout << "Enter a month from the Gregorian Calendar: "; cin >> month; cout << "Enter a day from the Gregorian Calendar: "; cin >> day; h = (day + (13 * (month + 1) / 5) + (year) + (year / 4) - (year / 100) + (year / 400)) % 7; if (h == 1) { cout << "The day is Sunday."; } if (h == 2) { cout << "The day is Monday."; } if (h == 3) { cout << "The day is Tuesday."; } if (h == 4) { cout << "The day is Wednesday."; } if (h == 5) { cout << "The day is Thursday."; } if (h == 6) { cout << "The day is Friday."; } if (h == 7) { cout << "The day is Saturday."; } return 0; }``````
Last edited on
Topic archived. No new replies allowed.