Thread: sqrt function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    30

    sqrt function

    this is another simple (i think) function that i have to complete for an assignment. the assignment description is:
    Write a program with a function called mySquareRoot. In main, prompt the user for a number (a double), then – by calling the mySquareRoot function – calculate and display the square root of the number. Use the standard cmath function to calculate the square root. Stop processing numbers when the user enters a zero.
    Code:
    #include <iostream>
    #include <cmath>
    using namespace std;
    
    int num;
    
    double mySquareRoot(int num)
    {
        return sqrt(num);
    }
    
    int main()
    {
       
        do
        {
            cout << "Enter a number (a double): ";
            cin >> num;
            cout << "The square root is " << mySquareRoot;
        } while (num != 0);
    }
    i am pretty sure my main program is right (with the do..while loop), but my function obviously isnt working correctly. it wont compile correctly, so i dont even know if i am getting close.

    thanks for help
    Last edited by kbpsu; 04-01-2009 at 02:43 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. Sqrt() Function
    By tmoney$ in forum C Programming
    Replies: 4
    Last Post: 04-22-2003, 04:31 PM