Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Math.Sqrt() problem.  (Read 4238 times)

0 Members and 1 Guest are viewing this topic.

Zach7

  • Guest
Math.Sqrt() problem.
« on: July 01, 2006, 10:00:16 PM »
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?
« Last Edit: July 01, 2006, 10:13:21 PM by Zach7 »

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Math.Sqrt() problem.
« Reply #1 on: July 02, 2006, 03:24:48 AM »
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-)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Zach7

  • Guest
Re: Math.Sqrt() problem.
« Reply #2 on: July 02, 2006, 07:06:21 AM »
Aha! So there is a math library. Thank you so much!