Results 1 to 4 of 4

Thread: Square Root - sqrt?

  1. #1

    Thread Starter
    Lively Member floppes's Avatar
    Join Date
    May 2001
    Location
    Darmstadt, Germany
    Posts
    99

    Square Root - sqrt?

    Hi!

    I'm very new to VC++ and need to get the square root of a number.

    In VB i would use Sqrt(n)... but how in VC++?

    I am making an MFC application.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Are you new to C++ or Windows programming with C++ I would SERIOUSLY suggest if the former, that you learn the language before trying to use MFC. Actually, scrap MFC altogether and use the API But in answer to your question...
    Code:
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    int main() {
        float fNum = 5.4f;
    
        cout << sqrt(fNum) << endl;
    
        return 0;
    }
    http://www.cplusplus.com/ref/cmath/sqrt.html
    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

  3. #3

    Thread Starter
    Lively Member floppes's Avatar
    Join Date
    May 2001
    Location
    Darmstadt, Germany
    Posts
    99
    I read a book about C++ (Jesse Liberty - Teach yourself C++ in 21 Days). Ok, I read until day 6

    On its CD was an online version of "Teach yourself Visual C++ in 21 days", and I have started with this today (I'm on day 3).

    I don't have problems with the C++ syntax, I can already program in PHP, HTML, VB and Delphi.

    I only wanted to write a short pi-algorithmus with Visual C++, and needed the square root function. I forgot this line: #include <cmath>

    Now it works, thanks for your help!

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Just don't trip up on pointers and inheritance which is something that MFC uses in spades and can really mess you up.
    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