diff --git a/main.cpp b/main.cpp index db351ef..7d3799a 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,5 @@ +#include + using namespace std; int main() @@ -10,14 +12,31 @@ int main() { cout<<"Enter a whole number: \n"; cin>>num1; + + while (!(cin >> num1)) // <<< note use of "short circuit" logical operation here + { + cout << "Please enter the number " < endl; + cin.clear(); + cin.ignore(); // NB: preferred method for flushing cin + } + + cout<<"Enter another whole number: \n"; cin>>num2; + while (!(cin >> num2)) // <<< note use of "short circuit" logical operation here + { + cout << "Please enter the number " < endl; + cin.clear(); + cin.ignore(); // NB: preferred method for flushing cin + } - if( num1 = num2 ) + if( num1 == num2 ) { cout<<"Numbers should be different!\n"; repeat = true; } + else + repeat = false; }while(repeat); cout<<"Increasing order: "; @@ -32,4 +51,3 @@ int main() return 0; } -