I'm writing a program where there are switch and if statements. The characters that the statements require in order to proceed are either F,I,A (and their lowercase counterparts).
When the user inputs something invalid, say the character S, how do I terminate the program?
// Example program
#include <iostream>
#include <string>
int main()
{
char ch = 'X';
std::cout << "Enter F, I, or A to continue: ";
std::cin >> ch;
bool good = false;
switch (ch) {
case'F':
case'f':
good = true;
break;
case'I':
case'i':
good = true;
break;
case'A':
case'a':
good = true;
break;
default:
good = false;
};
if (good)
{
std::cout << "Good!\n";
// do another stuff
}
else
{
std::cout << "Bad! Program over = very yes.\n";
}
}