1. ## Zeller's Formula

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! 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;
}``` 2. http://mathforum.org/dr.math/faq/faq.calendar.html

Using integers will cause integer arithmetic to be performed which will cause the decimal to be truncated. Here is an example:
Code:
```int int1 = 10;
int int2 = 7;
int answer = int1/3 + int2/4;
You can get remainders with the "modulus" operator or remainder operator: %. Here is an example:
Code:
`cout<<int1%3<<endl; //1`
These are horrible parameter names:
Code:
`string DayoftheWeek(int a,int b, int year)`
What is an 'a'? What is a 'b'? 3. ## Follow-up Zeller's Originally Posted by 7stud
http://mathforum.org/dr.math/faq/faq.calendar.html

Using integers will cause integer arithmetic to be performed which will cause the decimal to be truncated. Here is an example:
Code:
```int int1 = 10;
int int2 = 7;
int answer = int1/3 + int2/4;
You can get remainders with the "modulus" operator or remainder operator: %. Here is an example:
Code:
`cout<<int1%3<<endl; //1`
These are horrible parameter names:
Code:
`string DayoftheWeek(int a,int b, int year)`
What is an 'a'? What is a 'b'?
Where do you suggest I put that in? 4. Maybe write it a little bigger next time, my vision... it's not so good.

He didn't tell you to put anything in, he was fixing your work for you, which you so unappreciativly didn't accept. Just turn your ints into floats, find remainders with modulus , and use more meaningful variable names. 5. ## I'm sorry

I wasn't trying to be rude, I just thought it was better understandable to make the writing bigger. And hey I appreciate your help, I am just sort of stressed out, I don't know what I got myself into...

Thanks for all your help, and any other suggestions would be great, it helps I just don't understand ... 6. O and hey, can you tell me why I still keep getting the wrong weekday? What do you see as wrong in my code? 7. Strange, I have another different zeller's algorithm here, is this valid?

Code:
```if(month < 3) { mp = 0; yp = year-1; }
else { mp = int(0.4*month+2.3); yp = year }
t = int(yp/4)-int(yp/100)+int(yp/400);
return(365*year+31*(month-1)+day+t-mp)%7;```
Sometimes it outputs negative numbers, you will have to add 7 to it. Popular pages Recent additions 