Your isLeapYear function is returning "year" at the end instead of false. Since year is never non-zero, it's always interpretted as true. But isLeapYear's logic is wrong in any case.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
bool isLeapYear(int year) {
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0)
return true;
else
return false;
}
else // is divisible by 4 but not by 100
return false; // so this should return true
}
else // This part ...
return false; // ... isn't needed ...
return false; // ... since it returns false here anyway
}
|
So it simplifies down to:
1 2 3 4 5 6 7 8
|
bool isLeapYear(int year) {
if (year % 4 == 0)
if (year % 100 == 0)
return (year % 400 == 0);
else
return true
return false;
}
|
returnWeekDay always prints "Sunday" because it initializes dayOfWeek to 0 and then the first if statement is true. You need to pass in dayOfWeek as a parameter.
Also, getInput is not actually returning anything to main. year, month and day in main are totally separate variables from the ones declared in getInput. It needs to be something like:
1 2 3 4 5 6 7 8 9
|
// Called like this:
int year, month, day;
getInput(year, month, day);
// Declared like this:
void getInput(int &year, int &month, int &day) {
// don't declare year, month or day as local variables!
cin >> year >> month >> day;
}
|
I'm not quite sure what's happening in these two lines in main. I don't even understand why they compile.
1 2
|
int getCenturyValue(century);
int getYearValue(yearValue);
|
Ultimately, they should be something like
1 2
|
int century = getCenturyValue(year);
int yearValue = getYearValue(year);
|
Note that I've moved the declarations of century and yearValue to that point so they should be removed from the beginning of main. Modern style is to declare variables near the point of first use so they can be created with a useable value.
And those functions then become:
1 2 3 4 5 6
|
int getCenturyValue(int year) {
return year / 100;
}
int getYearValue(int year) {
return year % 100;
}
|
Those functions may be overkill, though.
A stylistic point:
1 2 3 4 5 6
|
//Instead of this
int year = int();
//write this
int year = 0;
//or the ultra-modern:
int year{};
|
There's never ever any reason to do this
|
std::string weekDay = std::string();
|
strings (and all properly made class-based objects) self-initialize to a default value.