Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Objects Loops and Final Touches Static Members

CalculateHypotenuse - Wrong Math Error

I have a very simple code to get the solution to this problem, yet it's telling me that my math is incorrect... I've tested the code in debugging and get correct answers, any ideas whats going on?

RightTriangle.cs
namespace Treehouse.CodeChallenges
{
    class RightTriangle
    {
        public static double CalculateHypotenuse (double a, double b)
        {
            return ((a*a) + (b*b));             
        }
    }
}

1 Answer

Kevin Gates
Kevin Gates
15,052 Points

You're formula is wrong. The hypotenuse formula is: The square root of a-squared + b-squared.

See here for more information: https://www.miniwebtool.com/hypotenuse-calculator/

Therefore you will want to implement this C# method: https://docs.microsoft.com/en-us/dotnet/api/system.math.sqrt?view=netframework-4.7.2