-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcin_ex.cpp
26 lines (25 loc) · 823 Bytes
/
cin_ex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;
int main() {
int input_var = 0;
// Enter the do while loop and stay there until either
// a non-numeric is entered, or -1 is entered. Note that
// cin will accept any integer, 4, 40, 400, etc.
do {
cout << "Enter a number (-1 = quit): ";
// The following line accepts input from the keyboard into
// variable input_var.
// cin returns false if an input operation fails, that is, if
// something other than an int (the type of input_var) is entered.
if (!(cin >> input_var)) {
cout << "You entered a non-numeric. Exiting..." << endl;
break;
// exit the do while loop
}
if (input_var != -1) {
cout << "You entered " << input_var << endl;
}
} while (input_var != -1);
cout << "All done." << endl;
return 0;
}