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

Code is not compiling..what am I missing here?

So I followed the prompt and implemented the two methods, CalculateHypotenuse and the Sqrt method, I believe, that are required by this challenge. However, I kind of feel that my code and my logic is missing something but I can't put my finger on it.

Am I on the right track? What is my thought process missing here?

RightTriangle.cs
namespace Treehouse.CodeChallenges
{
    class RightTriangle
    {
        public static double CalculateHypotenuse(double leg1, double leg2) //here I called the static method CalculateHypotenuse
        {
            Leg1 = leg1;
            Leg2 = leg2; 

            Hypotenuse hypotenuse = new Hypotenuse();  //created the object hypotenuse using a constructor
            Hypotenuse = hypotenuse; 
        }

            private static double Sqrt(double hypotenuse)  // method needed to generate Square root of sum of legs of triangle
            {
               return hypotenuse.Sqrt // the method should return a double    
            } 

   } 

}

1 Answer

It looks like you might be overthinking this. You'll need to square each side, then add them together, and then find the square root of the total. Try using

System.Math.Pow();

Also,

CalculateHypotenuse(double leg1, double leg2)

is supposed to be a method, but I think you're confusing it with a constructor for a class. This can all be done in one method, even though you could use more. That makes it more complicated, though.

I hope this gets you going in the right direction!