#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    36
    Rep Power
    11

    term does not evaluate to a function


    Yes, I have been getting this area in a program I have been writing C2064 term does not evaluate to a function. The syntax of my function is:

    void AreaTriangle(float side1, float side2, float side3)
    {
    float area, sum;
    sum = 1/2(side1 + side2 + side3);
    return cout << "Area = " << sqrt (sum (sum - side1) (sum - side2) (sum - side3));
    }

    And I am just not sure what this means. I am just a beginner to C++, but is seems to me, of what I know. That this is indeed a good function. But if I could get some help, it would be highly appreciated.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,625
    Rep Power
    4247
    >>sum = 1/2(side1 + side2 + side3);
    You're missing an * in the equation. You have to write this as
    sum = 1/2.0 * (side1 + side2 + side3);

    On top of that, you can't return from cout. Also your function is declared as void, which means it can't return anything.
    Code:
    void AreaTriangle(float side1, float side2, float side3) 
    { 
         float area, sum; 
         sum = 1/2.0 * (side1 + side2 + side3); 
         cout << "Area = " << sqrt (sum * (sum - side1) * (sum - side2) * (sum - side3)); 
    }
    Last edited by Scorpions4ever; September 9th, 2003 at 06:53 PM.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    He also does not use the variable area. Perhaps he wishes to calculate it, print it, and then also return it, like so:

    Code:
    float AreaTriangle(float side1, float side2, float side3) 
    { 
         float area, sum; 
         sum = 1/2.0 * (side1 + side2 + side3);
         area = sqrt (sum * (sum - side1) * (sum - side2) * (sum - side3));
         cout << "Area = " << area;
         return (area);
    }
    Also, Gustavo, you should look up why 1/2.0 is needed instead of just 1/2. The difference is integer division (which returns an integer), and floating point division (since one of the values is a floating point number, the other is converted into a floating point number, and the result is a floating point number). If you do not understand this, this type of bug will catch you all the time.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    36
    Rep Power
    11
    I'm having another bit of trouble with that function. I made those changes... and thanks for the feedback... but now I can not get the area to display, which I need "Area = value of area" to display. What I have now is:
    float AreaTriangle(float side1, float side2, float side3)
    {
    float area, s;
    s = 1/2.0 * (side1 + side2 + side3);
    area = sqrt (s * (s - side1) * (s - side2) * (s - side3));
    cout << "Area = " << area << endl;
    return (area);

    }


    And I call on it but I just get back Area = 00 each time.
    Again, I will much appreciate any help on this.
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,162
    Rep Power
    2222
    Originally posted by Gustavo
    I'm having another bit of trouble with that function. I made those changes... and thanks for the feedback... but now I can not get the area to display, which I need "Area = value of area" to display. What I have now is:
    float AreaTriangle(float side1, float side2, float side3)
    {
    float area, s;
    s = 1/2.0 * (side1 + side2 + side3);
    area = sqrt (s * (s - side1) * (s - side2) * (s - side3));
    cout << "Area = " << area << endl;
    return (area);

    }


    And I call on it but I just get back Area = 00 each time.
    Again, I will much appreciate any help on this.
    Stupid question: did you include the math header file?:
    #include <math.h>

    If you did not, then the compiler should have warned you that it could not find sqrt(), so it assumed that it returns int. Then when sqrt got linked in with your program, the parameters to it and its output got converted to int's. End result, totally wrong return value.

    I fell for that too in my very first C program. Yes, they did have C compilers way back then.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    36
    Rep Power
    11
    No, I am sorry... I did not say that I did... Yes, I did include the math header. Sorry for not specifing.
  12. #7
  13. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,162
    Rep Power
    2222
    OK, what are your input values? Also try expanding them by a factor of 100 or 1000 and see what your results are.

    Anyway, if we can see your input values and the function's return value, we might see what's happening.

IMN logo majestic logo threadwatch logo seochat tools logo