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 trialAndrew Winkler
37,739 PointsSo I don't get why this is not working... It's a static method for the Pythagorean theorem.
Welp. Here's my code:
using System.math;
namespace Treehouse.CodeChallenges
{
class RightTriangle
{
double a, b, c;
}
public static CalculateHypotenuse(double a, double b)
{
c = math.Sqrt(a * a + b * b);
return c;
}
}
1 Answer
Ryan Sheppard
2,866 PointsA few problems here...
- Your CalculateHypotenuse method isn't in a class -- methods cannot exist in a namespace.
- Your CalculateHypotenuse method doesn't have a return value -- you want it to return a double.
- Your using System.math; directive should read using System; -- Math is a class, not a namespace.
- math in your CalculateHypotenuse method should read Math.Sqrt -- note capitalized 'M'.
- Static methods cannot access instance members, so your CalculateHypotenuse method can't actually access the c field.
This is what you were probably going for:
using System;
namespace Treehouse.CodeChallenges
{
class RightTriangle
{
public static double CalculateHypotenuse(double a, double b)
{
return Math.Sqrt(a * a + b * b);
}
}
}