September 9th, 2003, 05:58 PM

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.
September 9th, 2003, 06:13 PM

>>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
September 9th, 2003, 07:29 PM

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.
September 9th, 2003, 07:36 PM

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.
September 9th, 2003, 07:56 PM

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.
September 9th, 2003, 08:00 PM

No, I am sorry... I did not say that I did... Yes, I did include the math header. Sorry for not specifing.
September 9th, 2003, 10:33 PM

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.