1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Another C++ Error, an "operand has type double...' "

Discussion in 'Programming & Webmastering' started by Atnevon, Jul 2, 2008.

  1. Atnevon

    Atnevon

    Joined:
    Sep 5, 2007
    Messages:
    443 (0.18/day)
    Thanks Received:
    29
    Hello Agian everyone.

    I'm not to sure what could be doing this, as to me, it looks right. This is another assignment for entry C++. I know I sound like a newb asking for help agian, but then agian, what are forums for at time lie this?

    Now, I have to use value returning functions in this assignment. I need to have the functions as main(), getHoursWorked(), getPayRate(), and calcGross() all together to calculate someones paycheck for the week.

    So this sounds like a simple "Pay = hours * rate", just a little overdone (if you ask me. Then again, I don;t know better at this point, so if I'm jumping the gun, please let me know)

    So I get all my kinks worked out, except this one line where I do the calculations for calcGross(). I have 2 errors from my build log. They say this:

    error C2296: '*': illegal, left operand has type 'double(_cdecl*)(void)'
    error C2297: '*': illegal, right operand has type 'double(_cdecl*)(void)'



    Now, I'm not sure why I'm getting this. My arithimtic setup looks correct to me, so why would I get this?

    I'm using Microsoft C++ Visual Studio Express 2005 for reference.

    Now for the moment of joy:
    Thank you all for helping.

    P.S. - I was not sure to post this in my last thread, or make a new one. I figured, well, new problem and situation, which altogether is a different topic, so new thread. If I am wrong, pleas correct me too.

  2. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.09/day)
    Thanks Received:
    5,615
    Location:
    Cheeseland (Wisconsin, USA)
    Since you are calling functions shouldn't this line in "calcGross()" look like ...

    gross = getHourseWorked() * getPayRate();

    Not great with C++, so just a guess. You need to include the parenthesis in C# when calling a function.
    I think when you exclude the parenthesis you are accessing a pointer to the function instead of calling it.
    Or something like that :D
  3. Atnevon

    Atnevon

    Joined:
    Sep 5, 2007
    Messages:
    443 (0.18/day)
    Thanks Received:
    29
    Tried the parenthesis, and got this:

    [​IMG]
    [​IMG]
  4. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.09/day)
    Thanks Received:
    5,615
    Location:
    Cheeseland (Wisconsin, USA)
    That's because you are declaring calcGross with two input parameters and not calling it with any in main().

    Since you are calling the two functions from within calcGross, just declare it as
    Code:
    double calcGross()
    {
        double gross = 0.0;
        gross = getHoursWorked() * getPayRate();
        return gross;
    }
    
    Last edited: Jul 2, 2008
    Atnevon says thanks.
  5. Atnevon

    Atnevon

    Joined:
    Sep 5, 2007
    Messages:
    443 (0.18/day)
    Thanks Received:
    29
    Kreij, I love you so much.

    I tweeked that and my main () and finally got it. Now I see what my error was. I was treating the calcGross like an a magic task, and not a value returning function like getHours and getRate.

    I guess what you suggested just pushed me to fix it. You may have nudged me answer, but it helped me to understand my error and learn the concept. BAM!! Once agian, learning has occured. Thank you so much, and here is the pretty result:

    Last edited: Jul 2, 2008
  6. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.09/day)
    Thanks Received:
    5,615
    Location:
    Cheeseland (Wisconsin, USA)
    If you want to lighten the code a bit consider the following ...

    Code:
    double calcGross()
    {
        double gross;  // no need to give it a value
        return gross = getHoursWorked() * getPayRate();
    }
    
    Saves a little typing !

    also ...
    Code:
    int main()
    {
        cout << fixed << setprecision(2) << "Total Pay for Week = $" << calcGross() << endl;
        return 0;
    }
    
    No need to have totalPay variable at all then.

    Good job !! :toast:
    Atnevon says thanks.
  7. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.09/day)
    Thanks Received:
    5,615
    Location:
    Cheeseland (Wisconsin, USA)
    Oh ... and a couple of comments on what you posted ...
    That is exactly what we are here for. Never be afraid to ask. No question is too basic.
    No one is born knowing how to program, and you have to start somewhere.

    New thread for new problem is fine as long as you are not just making a new thread to continue an existing problem

    If you are a guy ... we have may have problems.
    If you are a girl ... Mrs. Kriej may have problems
    :roll:

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page