Can anyone please help? I really don't understand what's wrong with my program. Whenever I try to compile it, I end up with the phrase:
prog.cpp: In function ‘int main()’:
prog.cpp:30:18: error: ‘year’ was not declared in this scope
isfourdigit(year);
Whoops, I'll fix that. Also, doesn't it count that I declare the "year" variable in the bool functions? Sorry, I'm still a beginner and don't understand much. XD
On line 23, for example, you try to pass the variable 'year' as a parameter to your function, but there isn't any such variable defined in main(). What value/variable where you trying to pass to it?
Basically, I wanted int main() to perform the bool functions so that "year" can be assigned the value of 1 or 0.
For example, in line 22, I declared the function so that it would have to skip to line 49 and calculate whether "year" is 1 or 0. After that, the bool isfourdigit function will return the data to int main so that it can do the next procedures.
I'm just not sure if I declared the functions in int main correctly, if the data was really returned, or if my logic is correct.
bool isfourdigit(shortint yearNumber)
{
if (yearNumber < 1000 || yearNumber > 9999)
{
returnfalse; // You originally had 'year = 1;' here (presumably corresponding to 'true'),
// but I felt that returning false was more appropriate since the function
// is called 'isfourdigit' and if we're in this branch of the if statement,
// then the number is NOT four digits.
}
else
{
returntrue;
}
}
bool isleapyear(shortint yearNumber)
{
// Similar to above
(Basically, make yearNumber your parameter and return true or false instead of setting a year variable).
Your function calls in main would then simply be
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
if (!isfourdigit(yearNumber)) // if NOT four digits --
{ // makes more sense than "if 'is four digits' is 1 ( == true?)"
cout << "Error: Enter a 4-digit year!";
}
else
{
if (!isleapyear(yearNumber))
{
cout << "Year " << yearNumber << " is an ordinary year.";
}
else
{
cout << "Year " << yearNumber << " is a leap year.";
}
}