Hi, this is my first post on this forum! I've just started to program in c++ in school, and I've already got a question, that I just can't seem to find out on the web.
I have to write a program that calcucates a hypotenuse of an rectangular(right) triangle.Things get messed up when I try to write down the forumula of the hypotenuse.
Are you allowed to use the math library or does everything have to be done with just loops and math? I can show you either way, but they're quite different.
Let's not fool ourselves. The only way to properly calculate a square root is with sqrt(), defined in cmath.
pow(), also in cmath, calculates any power (as long as it's valid, of course).
The other way...well...it's complicated for anything but whole number roots.
Will they be wanting decimal answers for the hypotenuse or are they only checking the special case triangles?
Yeah, helios is pretty much right. I mean, there are methods for loop calculating square roots, but they're not very accurate (unless you use one of the really complicated ones).