Back to General discussions forum
I always get answers like 2.01894e+06. I've seen on this forum that another coder had a similar problem but the admin didn't specify in details what he modified in the code. Why do you generate over the top values for the coordinates? The algorithm is good but why do you expect us to calculate such tremendous values if you don't have the computational capacity to do so? I even tried to split Heron's formula to A=sqrt(s)sqrt(s-a)sqrt(s-b)sqrt(s-c) instead of A= sqrt(s(s-a)(s-b)(s-c)).
Hi! Thanks for your message!
> The algorithm is good but why do you expect us to calculate such tremendous values if you don't have the computational capacity to do so?
Results in this problem are either integer, or halves (e.g. 0.5
) so I believe the algorithm
should work all right. Probably the trouble is somewhere in different place...
I had a look at your solution. Have you tried to print the result with something other than cout?
Perhaps this may help?
printf("%lf ", area);
Regretfully I'm not well acquainted with C++ to suggest how you can format cout
output better.
To print an integer or .5 I used
if(fabs(area-int(area))<.001) printf("%.0f ",area); // integer
else printf("%.1f ",area); // .5
Well, this should work even with not exact values, e.g. 14.4999999736
will do, I believe :)
Thanks, Quandray and Admin.
At first I didn't even thought that what you wrote is even C++. Still a lot to learn.
You are partially correct - at least printf
is old C
function and some people regard
it as not-C++
:)