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 trialTravis John Villanueva
5,052 PointsCan 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?
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
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsHey Travis, your CalculateHypotenuse method doesn't have a return type. You need to specify a return type like double, void, etc.
MR. 7
24,079 PointsTravis, 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
Travis John Villanueva
5,052 PointsThank you guys!
Travis John Villanueva
5,052 PointsThank you :)
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsNot a problem, Travis. If an answer helped you make sure to mark it as the Best Answer or at least upvote it.