Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
September 9th, 2003, 06:58 PM
 Gustavo
Contributing User

Join Date: Sep 2003
Posts: 36
Time spent in forums: < 1 sec
Reputation 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
September 9th, 2003, 07:13 PM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,536
Time spent in forums: 2 Months 3 Days 5 h 48 m 31 sec
Reputation Power: 4106
>>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));
} ```
__________________
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

Last edited by Scorpions4ever : September 9th, 2003 at 07:53 PM.

#3
September 9th, 2003, 08:29 PM
 Jason Doucette
jasondoucette.com

Join Date: Feb 2003
Posts: 378
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 11
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.

#4
September 9th, 2003, 08:36 PM
 Gustavo
Contributing User

Join Date: Sep 2003
Posts: 36
Time spent in forums: < 1 sec
Reputation 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.

#5
September 9th, 2003, 08:56 PM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,856
Time spent in forums: 3 Months 1 Day 5 h 8 m 22 sec
Reputation Power: 2199
Quote:
 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.

#6
September 9th, 2003, 09:00 PM
 Gustavo
Contributing User

Join Date: Sep 2003
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
No, I am sorry... I did not say that I did... Yes, I did include the math header. Sorry for not specifing.

#7
September 9th, 2003, 11:33 PM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,856
Time spent in forums: 3 Months 1 Day 5 h 8 m 22 sec
Reputation Power: 2199
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.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > term does not evaluate to a function