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; }




Reply With Quote