1.

Solve : Math.Sqrt() problem.?

Answer»

Im USING C++ Visual Studios 2005 express edition.
Im having a problem with this code:

float quad1(float a, float b, float c)

{

float d;

float e;

d=Math.SQRT(b*b-4*a*c);

e=(-b+d)/(2*a);

return e;

}


And here is the error:

c:\documents and settings\zach williamson\my documents\visual studio 2005\projects\workplace\workplace\workplace.cpp(42) : error C2065: 'Math' : undeclared identifier

c:\documents and settings\zach williamson\my documents\visual studio 2005\projects\workplace\workplace\workplace.cpp(42) : error C2228: left of '.Sqrt' must have class/struct/union

type is ''unknown-type''


Am I not including a library?I'm not a C++ programmer, but it doesn't appear you have a library reference. The following code will compile, whether it produces the right result is another matter.

Code: [SELECT][highlight]#include "math.h"[/highlight]

float quad1(float a, float b, float c)
{
float d;
float e;
[highlight]d=sqrt(b*b-4*a*c);[/highlight]
e=(-b+d)/(2*a);
return e;
}

I did find out that there is a difference between sqrt and Sqrt. I have no idea if this is significant to your program. 8-)Aha! So there is a math library. Thank you so much!



Discussion

No Comment Found