Results 1 to 10 of 10

Thread: Square Root...

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    I have been trying to take the square root of a number by doing this:

    Code:
    a = Sqr(25);
    And

    Code:
    a = Sqrt(25);
    I get the following error:error C2065: 'Sqr' : undeclared identifier

    and error C2065: 'Sqrt' : undeclared identifier....

    What is wrong?
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Include the math.h header file.

    Code:
    #include <math.h>
    ...
    double root = sqrt(nymber);
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  5. #5

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    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.
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What's at those lines?
    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

  7. #7

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    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;
    	}
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  9. #9

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    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;
    	}
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width