Ok I have tried a few ways to get this loop to terminate before using the ending variable in the function but I cannot seem to figure it out. This is just my latest attempt. I want this program to end when the user enters 0 but it always returns a square root for 0 (which of course is 0) before terminating. Did I really forget how to do this much while on vacation?
Code:#include <iostream> #include <cmath> using namespace std; void wierdsquareroot (double x) { cout << "The square root is " << sqrt(x) << endl; } int main () // Program calculates the square root of a number { double num; do { if (num != 0) { cout << "Enter a number (a double): "; cin >> num; wierdsquareroot (num); } }while (num != 0); }



LinkBack URL
About LinkBacks


