I was reading through my C++ book and testing out each thing I've been taught, only to find myself met with an usual problem.
When you run this code, it seems to work fine so long as you use any integer, but if you enter something else the code will go straight to the default case, display the message, and then close instantly - ignoring the fact that I set up a cin at the end of the programming at the end to 'pause' the system.
Is there a way I can check that my input is an integer?
//Just a program to test the switch function.
int main ()
cout << "Enter 1 or 2.\n";
cin >> choice;
cout << "You chose 1.\n";
cout << "You chose 2.\n";
cout << "You didn't choose 1 or 2.\n";
cin >> a;