I am still learning the function calls and I seem to be stuck when trying to add other functions together. I just want to add what the function is returning but I don't know how to get around the parameters which seems to make it not work properly.
I just need the dayofweek var to work by adding all the rest of the functions. I feel very close but I just can't seem to get it.
thanks for any help
#include <iostream>
usingnamespace std;
bool isLeapYear(int);
int getCenturyValue(int);
int getYearValue(int);
int getMonthValue(int, int);
int main()
{
char choice;
int month, day, year;
int dayofweek;
do
{
cout << "Enter a date in the form month day year, eg 4 24 1939 \n";
cin >> month >> day >> year;
//loop to not allow imporper dates
while (month > 12 || month < 0 || day >31 || day < 0 || year > 2018 || year < 0)
{
cout <<"Invalid date" << endl;
cout << "Enter a date in the form month day year, eg 4 24 1939 \n";
cin >> month >> day >> year;
}
isLeapYear(year);
getCenturyValue(year);
getYearValue(year);
getMonthValue(month, year);
// calculating the day of the week given the totals from other functions
dayofweek = (day + getMonthValue(month,year) + getYearValue(year) + getCenturyValue(year))%7;
// if statement to show day of week given the total
if (dayofweek = 0)
cout << month << "/" << day << "/" << year << "/" << " is a Sunday" << endl;
elseif (dayofweek = 1)
cout << month << "/" << day << "/" << year << "/" << " is a Monday" << endl;
elseif (dayofweek = 2)
cout << month << "/" << day << "/" << year << "/" << " is a Tuesday" << endl;
elseif (dayofweek = 3)
cout << month << "/" << day << "/" << year << "/" << " is a Wednesday" << endl;
elseif (dayofweek = 4)
cout << month << "/" << day << "/" << year << "/" << " is a Thursday" << endl;
elseif (dayofweek = 5)
cout << month << "/" << day << "/" << year << "/" << " is a Friday" << endl;
elseif (dayofweek = 6)
cout << month << "/" << day << "/" << year << "/" << " is a Saturday" << endl;
// runs another day of week when user enters "Y/y"
cout << "Do you want to simulate again? <Y or N>";
cin >> choice;
} while (choice == 'Y' || choice == 'y');
cout << "Thanks for playing!" << endl;
return 0;
}
//bool statment for leap year
bool isLeapYear(int year)
{
bool LeapYear = false;
LeapYear = ((year % 400 == 0) || ((year % 4 == 0) // leap year algorithm
&& (year % 100 != 0)));
return LeapYear;
}
//calculates the century value
int getCenturyValue(int year)
{
int remainder;
int centuryValue;
// pulls the year the user enters
year /= 100;
remainder = year % 4;
centuryValue = (3 - remainder) * 2;
return centuryValue;
}
//calculates the year value
int getYearValue(int year)
{
int remainder, yearValue;
//pulls the year the user enters
year %= 100;
remainder = year / 4;
yearValue = remainder + year;
return yearValue;
}
//calculates the month value
int getMonthValue(int month, int year)
{
int monthValue;
//uses the month the user enters
//uses the leap year function
switch (month)
{
case 1: if (isLeapYear(year))
monthValue = 6;
else monthValue = 0;
break;
case 2: if (isLeapYear(year))
monthValue = 2;
else monthValue = 3;
break;
case 3: if (isLeapYear(year))
monthValue = 3;
else monthValue = 3;
break;
case 4: if (isLeapYear(year))
monthValue = 6;
else monthValue = 6;
break;
case 5: if (isLeapYear(year))
monthValue = 1;
else monthValue = 1;
break;
case 6: if (isLeapYear(year))
monthValue = 4;
else monthValue = 4;
break;
case 7: if (isLeapYear(year))
monthValue = 6;
else monthValue = 6;
break;
case 8: if (isLeapYear(year))
monthValue = 2;
else monthValue = 2;
break;
case 9: if (isLeapYear(year))
monthValue = 5;
else monthValue = 5;
break;
case 10: if (isLeapYear(year))
monthValue = 0;
else monthValue = 0;
break;
case 11: if (isLeapYear(year))
monthValue = 3;
else monthValue = 3;
break;
case 12: if (isLeapYear(year))
monthValue = 5;
else monthValue = 5;
}
return monthValue;
}
Never mind... I did some debugging and realized my data was not passing as it should through the if/else statements. I changed them to all switch instead and it works just fine. Glad I was able to solve before anyone posted (you never know how long it will take for a response... so I post a little early sometimes).