|
-
Apr 15th, 2001, 08:54 AM
#1
Thread Starter
Frenzied Member
I have been trying to take the square root of a number by doing this:
And
I get the following error:error C2065: 'Sqr' : undeclared identifier
and error C2065: 'Sqrt' : undeclared identifier....
What is wrong?
-
Apr 15th, 2001, 09:09 AM
#2
Frenzied Member
Include the math.h header file.
Code:
#include <math.h>
...
double root = sqrt(nymber);
-
Apr 15th, 2001, 09:10 AM
#3
Monday Morning Lunatic
It's in the math.h system header, and since it's a library function it's all lower case:
Code:
float x = sqrt(5.4f);
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 15th, 2001, 09:11 AM
#4
Monday Morning Lunatic
I'll let you have that one 
parksie 1 - 1 Vlatko

I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 15th, 2001, 10:08 AM
#5
Thread Starter
Frenzied Member
Now I get the error:
C:\Programmer\Microsoft Visual Studio\MyProjects\Equation\equation.cpp(41) : error C2361: initialization of 'x' is skipped by 'default' label
C:\Programmer\Microsoft Visual Studio\MyProjects\Equation\equation.cpp(37) : see declaration of 'x'
Last edited by CyberCarsten; Apr 15th, 2001 at 10:12 AM.
-
Apr 15th, 2001, 10:23 AM
#6
Monday Morning Lunatic
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 15th, 2001, 11:06 AM
#7
Thread Starter
Frenzied Member
Code:
switch(choice){
case 1 :
// Do actions
break;
case 2 :
cout<<"Input a: ";
cin>>a;
cout<<""<<endl;
cout<<"Input b: ";
cin>>b;
cout<<""<<endl;
cout<<"Input c: ";
cin>>c;
d = b * b - 4 * a * c;
cout<<d<<endl;
double x = sqrt(d);
l1 = -b - x / 2 * a;
l2 = -b + x / 2 * a;
cout<<""<<endl;
cout<<"L1: " <<l1<<endl;
cout<<"L2: " <<l2<<endl;
break;
default:
cout<<"Choose either 1 or 2"<<endl;
}
-
Apr 15th, 2001, 11:20 AM
#8
Monday Morning Lunatic
You'll need to put the definition for double x before the switch block.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 15th, 2001, 11:46 AM
#9
Thread Starter
Frenzied Member
Now I get the following error:
:\Programmer\Microsoft Visual Studio\MyProjects\Equation\equation.cpp(16) : error C2086: 'x' : redefinition
C:\Programmer\Microsoft Visual Studio\MyProjects\Equation\equation.cpp(40) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
C:\Programmer\Microsoft Visual Studio\MyProjects\Equation\equation.cpp(41) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
C:\Programmer\Microsoft Visual Studio\MyProjects\Equation\equation.cpp(49) : error C2361: initialization of 'x' is skipped by 'default' label
C:\Programmer\Microsoft Visual Studio\MyProjects\Equation\equation.cpp(37) : see declaration of 'x'
Code:
double x;
switch(choice){
case 1 :
// Do actions
break;
case 2 :
cout<<"Indtast a: ";
cin>>a;
cout<<""<<endl;
cout<<"Indtast b: ";
cin>>b;
cout<<""<<endl;
cout<<"Indtast c: ";
cin>>c;
d = b * b - 4 * a * c;
cout<<d<<endl;
double x = sqrt(d);
cout<<x<<endl;
l1 = -b - x / 2 * a;
l2 = -b + x / 2 * a;
cout<<""<<endl;
cout<<"L1: " <<l1<<endl;
cout<<"L2: " <<l2<<endl;
break;
default:
cout<<"Choose either 1 or 2"<<endl;
}
-
Apr 15th, 2001, 11:51 AM
#10
Monday Morning Lunatic
Obviously you need to take out the second definition 
Try initialising it to 0 at the start, though.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|