-
invalid operands
Well I figured out why i was having so much trouble before with my code but now I have a new problem. I am getting a message when I compile it that says: invalid operands `int ()()' and `int' to binary `operator %'
This error occurs in my bool function. here is what my bool function looks like:
bool isLeapYear(int)
{
int LeapYear;
**if ((getYear % 400) == 0) LeapYear=true;
**else if ((getYear % 4) != 0 || getYear %100 == 0) LeapYear=false;
else LeapYear=true;
}
Any ideas on what could be causing this message would be greatly appreciated.
-
getYear looks like a member function. You always have to include the () after function calls.
-
Thank you very much for the help. That was the problem but now i have hit another problem. Any help would be appreciated once again. here is the problem:
Now i am getting a message that says: `LeapYear' cannot be used as a function
Here is what my code looks like for that section (The line with ** is the line that is getting this message):
bool isLeapYear(int)
{
int LeapYear;
if (getYear() % 400 == 0) LeapYear=true;
else if ( getYear() % 4 != 0 || getYear() % 100 == 0) LeapYear=false;
else LeapYear=true;
}
void doSpecificYear()
{
int LeapYear;
std::cout<<getYear()<<endl;
**if (LeapYear() == true)
std::cout<<"The year "<<getYear<<" is a leap year."<<endl;
else
std::cout<<"The year "<<getYear<<" is not a leap year."<<endl;
}
-
That's because the function is - isLeapYear(); However, this won't work as you haven't returned anything from the function (the local variable LeapYear should be a bool and it should be returned from your function) and your isLeapYear() function takes an integer as a parameter which is never used (should this be the year?).
-
Are you saying that where ever I have int LeapYear; i should have bool LeapYear; plus in the line that has the error message i should have:
if (isLeapYear() == true)
instead of:
if (LeapYear() == true)
-
Right. Except, you should get rid of the int parameter to isLeapYear() and make isLeapYear() return the variable LeapYear.