How to Enter a Cin w a -number to exit

Ask the user to enter any number except -100 (can be any number though, 100 is just a random number i picked) . If -100 is selected the program ends and displays Your number is invalid or whatever.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main(int argc, const char * argv[]) {
    int input = 0;
    bool run_menu = true;
    while (run_menu) {
        cout << "please enter any number " << endl;
        cin >> input;
        if (input != -100) {
            cout << "Your number is invalid or whatever" << endl;
            run_menu = false;
        }
    }
    return 0;
}
Last edited on
Topic archived. No new replies allowed.