Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey,
i am beginner, i made was asked to make a program that would make use of the heron's formula, and some knowledge regarding functions to find the area of a triangle.well, i did, but there was this one problem which i was not able to figure out.here it is " it's giving the wrong answer!!! ".
i don't know why. i went through each and every single step of the program and found no flaw. please help me find the flaw in my program.
to be a bit more specific:-
actually i programmed it in such a way that, when i give in the 3 sides of a triangle, it calculates the area of the triangle, by making use of the heron's formula,
well when i give in the values of the 3 sides, it calculates and gives the wrong answer(wrong area)!!
here's the code
C++
int ss=(se+sr+st)/2;
int ree=0;
ree=sqrt((ss-se)*(ss-sr)*(ss-st));
return ree;



--here is the link to the whole program just in case u want to take a look at it.

link
Posted
Updated 18-Aug-13 4:45am
v6
Comments
OriginalGriff 18-Aug-13 10:28am    
No. If you want help, then you have to help us, and make it as easy as possible for us to help you.
To that end, Post the problem: describe what your code does that you didn't expect, and what it doesn't do that you did expect.
Then, post the relevant code fragment that has the problem, rather than a link to a "random" site that has your full code.
Use the"Improve question" widget to edit your question.
A.U.K 18-Aug-13 10:46am    
i updated it
OriginalGriff 18-Aug-13 10:55am    
And almost immediately you had the solution!
See how much quicker it is if you help us to help you? :laugh:
A.U.K 18-Aug-13 10:59am    
thanks for letting me know about my mistake.
OriginalGriff 18-Aug-13 11:07am    
No problem!

1 solution

Instead of int use float or double. If you use float then use sqrtf, in case of double use sqrt. double gives you higher precision.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 18-Aug-13 23:36pm    
Oh gosh, int! What won't you see on the forum!? 5ed.
—SA
pasztorpisti 19-Aug-13 3:38am    
Thank you! At first sight I didn't spot it! Unexpected! :-) :-) :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900