invalid operands

This is a discussion on invalid operands within the C++ Programming forums, part of the General Programming Boards category; Well I figured out why i was having so much trouble before with my code but now I have a ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    30

    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.

  2. #2
    Ethereal Raccoon Procyon's Avatar
    Join Date
    Aug 2001
    Posts
    189
    getYear looks like a member function. You always have to include the () after function calls.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    30
    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;
    }

  4. #4
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    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?).
    zen

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    30
    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)

  6. #6
    Ethereal Raccoon Procyon's Avatar
    Join Date
    Aug 2001
    Posts
    189
    Right. Except, you should get rid of the int parameter to isLeapYear() and make isLeapYear() return the variable LeapYear.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  2. Quick question about invalid operands!
    By chocobo59 in forum C Programming
    Replies: 3
    Last Post: 12-03-2007, 10:50 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Need help with C program
    By ChrisH in forum C Programming
    Replies: 38
    Last Post: 11-13-2004, 12:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21