you only have to pass the variables you'll need in the function. not the ones you use to calculate stuff(like x,w,y,...)
and when you return a value from your function you don't have to put it in your arg list, do it like this: return_value=function(arg1,arg2);
and when u use switch(), make sure you add break; after every case. otherwise he will always take the default value.
Are you sure the formula for calculating the day is right? Because I entered my birthday and it came up with sunday, and I was born on a wednesday. I could be wrong, it was so long ago, and I was still very young. Or it could be the millenium bug
well here's the code:
Code:
#include <iostream> // cin, cout
#include <iomanip> // math library
#include <string> // string library
using namespace std; // introduces namespace std
string DayoftheWeek(int , int , int );
//prototype
int main(void)
{
int mon, day, year;
char YorN;
string WeekDay;
do
{
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)
//definition of function to find 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)//for remainder
{
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;
default: WeekDay = "Saturday";
break;
}return WeekDay;
}