Switch Case - Control Structure
How is a Switch case used in C++?
Use of "Switch Case" Control Structure.
compares the value of an expression against a list of integers or character constants.The list of constants are listed using the "case" statement along with a "break" statement to end the execution. If no conditions match then the code under the default statement is executed.
using namespace std;
cout << "Enter the day of the week between 1-7::";
cin >> day;
cout << "Monday";
cout << "Tuesday";
cout << "Wednesday";
cout << "Thursday";
cout << "Friday";
cout << "Saturday";
cout << "Sunday";
Enter the day of the week between 1-7::7
In the above Control Structure example the "switch" statement is used to find the day of the week from the integer input got from the user.