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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.