Return to Topic Menu | Computer Science Main Page | MathBits.com  | Terms of Use

Demo "switch" menu (with character expression).
This is a Program Fragment ...

//Sample using characters menu choices.

char choice;

//Menu
cout<<"Available modes of transport:\n"
cout<<"E - Enterprise"<<endl;
cout<<"M - Millennium Falcon"<<endl;
cout<<"T - Tie Fighter"<<endl;

cout<<"Please make your choice from the menu: ";
cin>>choice;     

switch (choice)
{
     case('E'):  {
                       cout<<"The Enterprise departs on"
                              <<" stardate 2067.3"<<endl;
                       cout<<"Be prompt!";
                       break;
                       }
     case('M'):  {
                       cout<<"The Falcon should depart at 1500 hours.\n";
                       cout<<"However, Han Solo is always late!"<<endl;
                       break;
                       }
     case('T'):  {
                       cout<<"The Tie Fighter has already departed.\n";
                       cout<<"You may want to use a transporter!";
                       break;
                       }
     default:   {
                     cout<<"\a\a\a\a\aPlease enter only E, M or T!!";
                     cout<<endl;
                     cout<<"Try again, please.";
                     }
}

 

 

 Return to Topic Menu | Computer Science Main Page | MathBits.com | Terms of Use