CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Threaded View

  1. #1
    Join Date
    Oct 2008
    Posts
    52

    Functions with one parameter problem

    Hey guys, I think I am very close on this problem but I dont know how to end my program after the zero is entered because it just continues to promt the question.

    Also we are not allowed to use global variables.. Is this a global variable?


    Code:
    /*	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. Use the 
    	follow screen shot as a guide.
    */
    
    
    #include <iostream>
    #include <string>
    #include <cmath>
    
    using namespace std; 
    
    double mySquareRoot (double num=0) 
    {  
        return sqrt(num); 
    } 
    void main () 
    { 
    
        double NewNum; 
        double num=0; 
    
        
        while(num != '0') 
        {cout << "Enter a number (a double): "; cin >> num; 
    
        NewNum = mySquareRoot(num); 
        cout << "The square root is " << NewNum << endl; 
    
        } 
        if (num =='0') 
            return;  
    }
    Attached Files Attached Files

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

Featured