0

Im not sure how to include a "checker" to prevent incorrect input pls help :( sorry, just started learning last night forgive me.. How should i do about this, without using if else statement or when should i be using that instead?

#include <iostream>
#include <iomanip>
using namespace std;
int main() 
{
int get_number;
char ch;
cout << "Hey! What is your number 1 OR 2?! :";
cin >> get_number;

switch (get_number)
{       
    case 1: cout << "You pressed 1/nPress anykey to continue!";
    break;

    case 2: cout << "You pressed 2/nPress anykey to continue!";
    break;

    default: cout << "Retry! 1 OR 2?! :";
        cin >> get_number;
}

cin.ignore(1, '/n');
cout << "Press any key to continue";
cin.get(ch);

return 0;
}
clicee
  • 1
  • 2
    Possible duplicate of [Check if input is integer type in C](https://stackoverflow.com/questions/4072190/check-if-input-is-integer-type-in-c) – Bob Swager Jul 15 '17 at 17:32
  • Possible duplicate of [Switch statement within while loop in C](https://stackoverflow.com/questions/16117322/switch-statement-within-while-loop-in-c) – EA-Lille Jul 16 '17 at 08:55

0 Answers0