Switch Statement Switch statement is another selection statement that you can use. The switch statement allows you to match multiple values with an expression. For each option, the behaviour could be different. The following If - Else Statement could be rewritten using a switch statement. #include <iostream> using namespace std; int main() { char opt; cout << "What is your marital status? \n" << "m-married, s-single, d-divorced, w-widowed \n" << ":"; if (opt == 'm') cout << "you entered married." << endl; else if (opt == 's') cout << "you entered single." << endl; else if (opt == 'd') cout << "you entered divorced." << endl; else if (opt == 'w') cout << "you entered widowed." << endl; else cout << "invalid option." << endl; return 0; } The above if-else statement cou...
Education for everyone!