I can't get this while loop to keep looping and not do a fast loop.
The full code is downloadable

while (num == 0) {
        cout << "Type in two values:\n";
        cin >> num;
        num1 += num;
        cin >> num;
        num2 += num;
        cout << "Which measurment unit do you want to use cm/m/in/ft?";
        cin >> un;

        cout << "\nValue 1: "<<num1;
        cout << "\nValue 2: " << num2 <<"\n";

        if (num1 > num2)
        {
            cout << "\nThe largest so far: " << num1;
            cout << "\nThe smallest so far: " << num2;
        }
        else if (num1 < num2) {
            cout << "\nThe largest so far: " << num2;
            cout << "\nThe smallest so far: " << num1;
        }
    
        cout << "\n";
        num = 0;
        

        
            
    }
Attachments
#include <iostream>
#include <cstdlib>

using namespace std;
inline void keep_window_open() { char ch; cin>>ch; }

double num;
double num1;
double num2;
double num3;
double knum1;
double knum2;
char term;
char un;
int main() {


	while (num == 0) {
		cout << "Type in two values:\n";
		cin >> num;
		num1 += num;
		cin >> num;
		num2 += num;
		cout << "Which measurment unit do you want to use cm/m/in/ft?";
		cin >> un;
		/*if ((unit != 'cm')||(unit != 'm')||(unit != 'in')||(unit != 'ft'))
		{
			cout << "ERROR! You were supposed to put cm or m or in or ft ";
		} */
		cout << "\nValue 1: "<<num1;
		cout << "\nValue 2: " << num2 <<"\n";

		if (num1 > num2)
		{
			cout << "\nThe largest so far: " << num1;
			cout << "\nThe smallest so far: " << num2;
		}
		else if (num1 < num2) {
			cout << "\nThe largest so far: " << num2;
			cout << "\nThe smallest so far: " << num1;
		}
	/*	if (num1 > num2)
		{
			cout << "\nThe larger value is: " << num1;
			cout << "\nThe smaller value is: " << num2;
		}
		else if (num1 < num2) {
			cout << "The Larger value is: " << num2;
			cout << "\nThe smaller value is: " << num1;
		}
		if (num1 == num2){
			cout << "\nThe numbers are equal";
		}
		else if (num1 <= num2){
			cout << "\nThe numbers are almost equal";
		}
		else if (num1 >= num2){
			cout << "\nThe numbers are almost equal";
		} 
		cout << "\nEnter a new number: ";
		cin >> num3; */
		cout << "\n";
		num = 0;
		

		
			
	}

keep_window_open();
return 0;
}
while (num == 0) {
cout << "Type in two values:\n";
cin >> num; // num isn't 0 if you enter anything but 0, no more while loop.

You said "keep looping", obviously it won't loop if num isn't 0

If you want it to loop forever, try doing this:
while(true) {
}

Then it will never end.

That's kind of bad though, so you should just use an exit value.

char input('a');
while( input != 'n' ) {
  std::cout << "Type n to quit.";
  std::cin >> input;
}

Edit: Oops, I lied. You put num=0; at the end.
What do you mean by keep looping?
Do you want the min/max of every value you've ever entered (not just 2 values)?
If so you'll need an array to store the data.

Edited 6 Years Ago by Unimportant: n/a

Well in the loop
I want it to ask for a number twice and declare those two numbers then compare them.
Then I want it to restart or close by asking whether or not you chose to.

This article has been dead for over six months. Start a new discussion instead.