Pythagorean Theorem problem not correct i think

Back to General discussions forum

NaolenBaolen     2025-01-11 23:02:44

This might be totally wrong but would someone be willing to double check if this is the case.

I think the answer for this problem is "reversed". Saying the triangle is Obtuse when its Acute and vice versa.

I thiink my answers are correct ( i cross checked with calculator). I get the same order, just that my O's are where the answers says the A's should be. I initially thought i just misplaced a '<' or '>', but when i checked with calculator i do indeed return Obtuse and Acute when I should (i think, its late, i might be brainfarting rn).

Hope my point gets across and thanks!

Rodion (admin)     2025-01-14 11:13:01
User avatar

Hi Friend!

Generally it may be good to have a look at the amount of solvers problem has - newly created problems of course have more chances to have bugs. This one was solved by 4000+ persons...

You current code is like this:

    if(someHyp > hyp){
        return ("O ");
    }else if(someHyp < hyp){
        return ("A ");
    }else{
        return ("R ");
    }

here someHyp is the value of hypotenuse you calculated for two given catheti (i.e. if triangle is right)

then you compare this right-triangle-hypotenuse with a given hypotenuse value... and for some reason decide that if it is larger, then triangle has obtuse angle. note: real hypotenuse is shorter than one you calculated for right triangle - this means it has smaller angle than right angle. obtuse couldn't be smaller :)

you can also modify your code to use "cosine theorem" which is a "generalization" of pythagorean - it simply outputs the angle you are interested in.

your code also has strange step of rounding and casting to int the calculated someHyp. I'm not sure but this may lead to wrong decisions rarely. you'd better either not round unnecessarily, or don't extract sqrt at all (instead raise hyp to square).

Please login and solve 5 problems to be able to post at forum