Hi ya'll I was wondering if someone was able to help me with Zeller's formula, I am trying to write a program to find the day of the week using his formula. I need to write a program that takes a date from the user and uses Zeller's Formula to determine the day of the week. I am to use a switch statement to convert the final day of week number given by zeller's into a day of the week string for output. Will someone please help me, and I need to use functions to make my program more readable. This is what I have, but it just is too complicated, I was wondering if someone could help me out a little bit, clean it up and make it actually work where I get the correct day? Please help I am appreciative of any help that can help me! :confused:
Code:#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
string DayoftheWeek(int , int , int );
int main()
{
int mon, day, year;
char YorN;
string WeekDay;
{
cout << "Enter the number of the month:";
cin >> mon; //month of year
cout << "Enter day of the month:";
cin >> day; //day of month
cout << "Enter the year:";
cin >> year; //year number
cout << "The day of the week for the date you have entered is: ";
WeekDay = DayoftheWeek(mon,day,year); //function call
cout << WeekDay;
cout << ".\n";
cout << "\n\n\nEnter Y to try another, N to stop.\n\t\t";
cin >> YorN;
}
while(YorN=='Y'||YorN=='y');
return 0;
}
string DayoftheWeek(int a,int b, int year)
//To find the day of week.
{
string WeekDay;
int c,d,w,x,y,z,r;
c = year % 100;
d = year / 100;
if(a <= 2)
{
a += 10;
}
else
{
a -= 2;
}
{
w = (13 * a - 1) / a;
x = c / 4;
y = d / 4;
z = w + x + y + b + c - 2 * d;
r = z % 7;
}
switch(r)
{
case 0: WeekDay = "Sunday";
break;
case 1: WeekDay = "Monday";
break;
case 2: WeekDay = "Tuesday";
break;
case 3: WeekDay = "Wednesday";
break;
case 4: WeekDay = "Thursday";
break;
case 5: WeekDay = "Friday";
break;
case 6: WeekDay = "Saturday";
break;
}
return WeekDay;
}