Advertisement
Guest User

C++ Problem Lab 5.2 - Updated

a guest
Nov 21st, 2014
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.34 KB | None | 0 0
  1. //
  2. // This program displays a hot beverage menu and prompts the user to
  3. // make a selection. A switch statement determines which item the user
  4. // has chosen. A do-while loop repeats until the user selects item E
  5. // from the menu.
  6.  
  7.  
  8. #include <iostream>
  9. #include <iomanip>
  10. using namespace std;
  11.  
  12. int main()
  13.  
  14. {
  15.     // Fill in the code to define an integer variable called number,
  16.     // a floating point variable called cost,
  17.     // and a character variable called beverage
  18.    
  19.     bool validBeverage;
  20.     char beverage;
  21.     float cost;
  22.     int number;
  23.    
  24.     cout << fixed << showpoint << setprecision(2);
  25.    
  26.     do {
  27.         cout << "Hot Beverage Menu" << endl << endl;
  28.         cout << "A: Coffee $1.00" << endl;
  29.         cout << "B: Tea $ .75" << endl;
  30.         cout << "C: Hot Chocolate $1.25" << endl;
  31.         cout << "D: Cappuccino $2.50" << endl << endl;
  32.        
  33.         // Fill in the code to read in beverage
  34.         cout << "Choose your beverage" << endl;
  35.         cin >> beverage;
  36.        
  37.         switch(beverage)
  38.        
  39.                 {
  40.                     case 'A': case 'B': case 'C': case 'D': case 'a': case 'b': case 'c': case 'd': validBeverage = true;
  41.                             break;
  42.                    
  43.                     default: validBeverage = false;
  44.                 }
  45.        
  46.         if (validBeverage == true)
  47.            
  48.         {
  49.             cout << "How many cups would you like?" << endl;
  50.             // Fill in the code to read in number
  51.             cin >> number;
  52.            
  53.             // Fill in the code to begin a switch statement that is controlled by beverage
  54.            
  55.             switch(beverage)
  56.            
  57.             {
  58.                 case 'a':
  59.                 case 'A': cost = number * 1.0; // Coffee
  60.                     cout << "The total cost is $ " << cost << endl;
  61.                     break;
  62.                
  63.                 // Fill in the code to give the case for Tea ( $0.75 a cup)
  64.                 case 'b':
  65.                 case 'B': cost = number * .75;
  66.                     cout << "The total cost is $ " << cost << endl;
  67.                     break;
  68.                    
  69.                 // Fill in the code to give the case for Hot Chocolate ($1.25 a cup)
  70.                 case 'c':
  71.                 case 'C': cost = number * 1.25;
  72.                     cout << "The total cost is $ " << cost << endl;
  73.                     break;
  74.                
  75.                 // Fill in the code to give the case for Cappuccino ($2.50 a cup)
  76.                 case 'd':
  77.                 case 'D': cost = number * 2.50;
  78.                     cout << "The total cost is $ " << cost << endl;
  79.                     break;
  80.                
  81.                 case 'e':
  82.                 case 'E': cout << " Please come again" << endl;
  83.                 break;
  84.                
  85.                 default:
  86.                 // Fill in the code to write a message indicating an invalid selection.
  87.                 cout << "Invalid selection, please try again" << endl;
  88.                    
  89.             }
  90.         }
  91.        
  92.        
  93.         // Fill in the code to finish the do-while statement with the
  94.         // condition that beverage does not equal E or e.
  95.     }
  96.         while (beverage != 'e' || beverage != 'E');
  97.        
  98.         // Fill in the appropriate return statement
  99.         return 0;
  100.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement