C++ examples for Statement:switch
The order of the case statements is not fixed. You can rearrange the statements to make them more efficient.
#include <iostream> using namespace std; int main()/*from w w w . j av a 2 s . c o m*/ { char choice; do { cout << "S - Sales \n"; cout << "A - Accounting \n"; cout << "E - Engineering \n"; cout << "P - Payroll \n"; cout << "What is your choice? "; cin >> choice; // Convert choice to uppercase (if they // entered lowercase) with the ASCII table. if ((choice>=97) && (choice<=122)) { choice -= 32; } // Subtract enough to make uppercase. } while ((choice!='S')&&(choice!='A')&& (choice!='E')&&(choice!='P')); switch (choice) { case ('E') : { cout << "\n Your meeting is at 2:30"; break; } case ('S') : { cout << "\n Your meeting is at 8:30"; break; } case ('A') : { cout << "\n Your meeting is at 10:00"; break; } case ('P') : { cout << "\n Your meeting has been " << "canceled"; break; } } return 0; }