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 trialUlysses Hall
1,469 PointsWhy error no "Math"
I get error that "Math" is not known. This works just fine in Visual Studio 2015
public static double CalculateHypotenuse(double sideA, double sideB) { return Math.Sqrt(Math.Pow(sideA, 2) + Math.Pow(sideB, 2));
}
namespace Treehouse.CodeChallenges
{
class RightTriangle
{
}
}
1 Answer
Joshua McMahon
6,778 PointsIt looks like everything is correct, but you haven't referenced the system namespace. Without this, the compiler doesn't know what Math.Sqrt and Math.Pow means, and is unable to proceed. As for this working in Visual Studio (if I were to hazard a guess), it is likely it attempts to reference common namespaces automatically when compiling, thus fixing some common coding mistakes.
The below code worked for me in the challenge, and I got the same error when leaving off the system namespace.
Error without System Namespace:
RightTriangle.cs(9,20): error CS0103: The name `Math' does not exist in the current context
Compilation failed: 1 error(s), 0 warnings
Solution:
using System;
namespace Treehouse.CodeChallenges
{
class RightTriangle
{
public static double CalculateHypotenuse (double a, double b)
{
return Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2));
}
}
}
Ulysses Hall
1,469 PointsUlysses Hall
1,469 PointsI thought that was it, but I didn't recognize how to add the using in the challenge and tried incorrectly to put the using statement in the challenge.
I thought I had tried to say System.Math..... in my answer; but I guess I hadn't because I just tried it and it did things just fine.
Thanks.