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

Travis John Villanueva
Travis John Villanueva
5,052 Points

Can you hint where is my error? The editor says i need to have a return type

I already assign the result to a type double, did i miss something here?

RightTriangle.cs
namespace Treehouse.CodeChallenges
{
    class RightTriangle
    {
        public static CalculateHypotenuse(double Height, double V)
        {
            Height=5.0;
            V=20.0;

            double res = Height / Math.Sin(V);
            return res;
        }
    }
}

3 Answers

Travis, here's a suggestion:

using System;

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

In your code, you did not add the using directive or the return type (double). The using directive is needed if you are to use the Math class without its associated namespace; otherwise, you need to add System to Math (System.Math). The return type (double) is what the CalculateHypotenuse method should return, so add it before CalculateHypotenuse.

Moreover, Pythagoras' Theorem is a2 + b2 = c2. Use a and b as parameters (to save on typing).

That said, you don't have to store the value in a variable, if you want to further save on typing.

I hope this helps! If you have any further questions, feel free to reach out.

Never Stop Learning