Hi, i'm having a little trouble with my Zeller's Algorithm problem. Everything seems to work fine unless the year is 1600, 1700, 1800, ect. I've been trying to figure out where i went wrong but to no avail. I'd appreciate any advice. Thanks.
#include <iostream>
#include <iomanip>
using namespace std;
void DisplayTitle();
void GetDate(int& inputmonth, int& inputday, int& inputyear);
int CalcDayofWeek(int monthnumber, int daynumber, int yearnumber);
void DisplayDay(int G);
int main()
{
int month, day, year, G;
DisplayTitle();
GetDate(month, day, year);
while (month != 0)
{
G = CalcDayofWeek(month, day, year);
DisplayDay(G);
GetDate(month, day, year);
}
return 0;
}
void DisplayTitle()
{
cout << "\n\n Zeller's Algorithm\n";
}
void GetDate(int& inputmonth, int& inputday, int& inputyear)
{
cout << "\n\n Enter Month (or 0 to exit) ";
cin >> inputmonth;
if (inputmonth != 0)
{
cout << "\n\n Enter day ";
cin >> inputday;
cout << "\n\n Enter year ";
cin >> inputyear;
}
}
int CalcDayofWeek(int monthnumber, int daynumber, int yearnumber)
{
int c, d, G;
c = yearnumber / 100;
if (monthnumber < 3)
{
monthnumber = monthnumber + 10;
d = (yearnumber % 100) - 1;
}
else
{
monthnumber = monthnumber - 2;
d = (yearnumber % 100);
}
G = (static_cast<int>((2.6 * monthnumber - .2) + daynumber + d + (d/4) + (c/4) - 2 * c) % 7);
if (G < 0)
{
G = G + 7;
}
return G;
}
void DisplayDay(int G)
{
switch (G)
{
case 0: cout << "\n The Day is Sunday"; break;
case 1: cout << "\n The Day is Monday"; break;
case 2: cout << "\n The Day is Tuesday"; break;
case 3: cout << "\n The Day is Wednesday"; break;
case 4: cout << "\n The Day is Thrusday"; break;
case 5: cout << "\n The Day is Friday"; break;
case 6: cout << "\n The Day is Saturday"; break;
default: cout << "\n Wrong Answer";
}
}