0

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?

#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);
}
1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by jae5086
0

Ok I figured it out, the input was inside the if statement.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.