I am new to C++. I have CodeWarrior, if that makes a difference. I can get this project to compile and receive input. But when it is suppose to output the weekday at the end of "entered is:", I only get "." What am I doing wrong? I have done the formulas manually, they all seem to work. Any help will be greatly appreciated.
//Project 4 - receives the number of a month, the day
//of a month, and a year, and returns the name of the
//day of the week on which that date fell or will fall
#include <iostream> // cin, cout
#include <iomanip> // math library
#include <string> // string library
using namespace std; // introduces namespace std
string DayoftheWeek(string, int, int, int, int, int, int, int, int, int, 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: ";
string DayoftheWeek(WeekDay); //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(string WeekDay, int mon, int a, int b, int c, int d, int w, int x, int y, int z, int r, int day, int year)
//definition of function to find day of week
{
a = mon;
b = day;
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";
case 1: WeekDay = "Monday";
case 2: WeekDay = "Tuesday";
case 3: WeekDay = "Wednesday";
case 4: WeekDay = "Thursday";
case 5: WeekDay = "Friday";
default: WeekDay = "Saturday";
}return WeekDay;
}



LinkBack URL
About LinkBacks



