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

Stepas Loiba
Stepas Loiba
11,180 Points

Need help with is your math correct in challenge.

Can't find reason why saying is your math correct,can some one have look in my code please ,thank you in advance.would be great help.

RightTriangle.cs
namespace Treehouse.CodeChallenges
{
    class RightTriangle
    {
        private static double a;
        private static double b;
        private static double c;

        public static double CalculateHypotenuse(double a , double b)
        {
            c = System.Math.Pow(c,2);
           return c = System.Math.Pow(a,2) + System.Math.Pow(b,2);   
        }
    }
}

I'm not sure what you were tasked to do but just from the initial overview, your method should just do the calculation, it should not set the class variable c. By removing the initialization of c (which is the class variable since the variable is not a parameter), and just returning the actual calculation should clean this method up and give you the proper calculation. If the class variables need to be initialized, then best practice is to use that in a constructor, you should be able to set a & b and use the calculation for c.

        public static double CalculateHypotenuse(double a , double b)
        {
           return System.Math.Sqrt(System.Math.Pow(a,2) + System.Math.Pow(b,2));   
        }

2 Answers

ceriannejackson
ceriannejackson
23,759 Points

Hi, you are returning c which is equal to a squared + b squared. This means you are returning the hypotenuse squared. You need to return the square root of c.

Hope that helps :)

Stepas Loiba
Stepas Loiba
11,180 Points

thank you for help,was very useful.have nice day.:)