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

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

// Sample using numbers as menu choices.
// Conversion program
 
int choice;

//Menu
cout<<"1.  LBS to OZS formula"<<endl;
cout<<"2.  Minutes to Seconds formula"<<endl;
cout<<"3.  Months to Weeks formula"<<endl;

cout<<"Which formula would you like to see? ";
cin>>choice;     

switch (choice)
{
     case(1):  {
                     cout<<"Conversion to ounces:"<<endl;
                     cout<<"16 ozs. = 1 pound";
                     break;
                     }
     case(2):  {
                     cout<<"Conversion to seconds:"<<endl;
                     cout<<"60 seconds = 1 minute";
                     break;
                     }
     case(3):  {
                     cout<<"Conversion to weeks:"<<endl;
                     cout<<"4 weeks = 1 month";
                     break;
                     }
     default:   {
                     cout<<"\a\a\a\a\aPlease enter only 1, 2 or 3!!";
                     cout<<endl;
                     cout<<"Try again, please.";
                     }
}

 

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