Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I don\'t konw what\'s wrong with my codes. When I entered the letter \"E\", the

ID: 646584 • Letter: I

Question

I don't konw what's wrong with my codes. When I entered the letter "E", the program didn't stop or exit.

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int number;// Fill in the code to define an integer variable called number,
float cost;// a floating point variable called cost,
char beverage;// and a character variable called beverage

bool validBeverage;

cout << fixed << showpoint << setprecision(2);

do
{
  cout << endl << endl;
  cout << "Hot Beverage Menu" << endl << endl;
  cout << "A: Coffee         $1.00" << endl;
  cout << "B: Tea            $ .75" << endl;
  cout << "C: Hot Chocolate $1.25" << endl;
  cout << "D: Cappuccino     $2.50" << endl <<endl << endl;
  
  cout << "Enter the beverage A,B,C, or D you desire" << endl;
  cout << "Enter E to exit the program" << endl << endl;
  cin >> beverage; // Fill in the code to read in beverage
  
  switch(beverage)
  {
  case 'a':
  case 'A':
  case 'b':
  case 'B':
  case 'c':
  case 'C':
  case 'd':
  case 'D': validBeverage = true;
       break;
  default:   validBeverage = false;
  }

  if (validBeverage)
  {
   cout << "How many cups would you like?" << endl;
   cin >> number; // Fill in the code to read in number
  }

  switch(beverage)// Fill in the code to begin a switch statement
      // that is controlled by beverage
  {
  case 'a':
  case 'A': cost = number * 1.0;
       cout << "The total cost is $ " << cost << endl;
    break;

  case 'b':
  case 'B': cost = number * .75;
   cout << "The total cost is $ " << cost << endl;// Fill in the code to give the case for tea ( $0.75 a cup)
   break;

  case 'c':
  case 'C': cost = number * 1.25;
   cout << "The total cost is $ " << cost << endl;// Fill in the code to give the case for hot chocolate ($1.25 a cup)
   break;

  case 'd':
  case 'D': cost = number * 2.50;
   cout << "The total cost is $ " << cost << endl;// Fill in the code to give the case for cappuccino ($2.50 a cup)  
   break;
  
  case 'e':  
  case 'E': cout << " Please come again" << endl;
       break;
  default:cout << "Your selection is not on the list" << endl;// Fill in the code to write a message
                  // indicating an invalid selection.
    cout << "Try again please" << endl;
  }


}

while (beverage != 'E' || beverage != 'e');// Fill in the code to finish the do-while statement with the
              // condition that beverage does not equal E or e.
cin.get();
return 0;// Fill in the appropriate return statement
}

Explanation / Answer

#include
#include
using namespace std;

int main()
{
    int number;// Fill in the code to define an integer variable called number,
    float cost;// a floating point variable called cost,
    char beverage;// and a character variable called beverage

    bool validBeverage;

    cout << fixed << showpoint << setprecision(2);


    do
    {
       cout << endl << endl;
       cout << "Hot Beverage Menu" << endl << endl;
       cout << "A: Coffee $1.00" << endl;
       cout << "B: Tea $ .75" << endl;
       cout << "C: Hot Chocolate $1.25" << endl;
       cout << "D: Cappuccino $2.50" << endl <   
       cout << "Enter the beverage A,B,C, or D you desire" << endl;
       cout << "Enter E to exit the program" << endl << endl;
       cin >> beverage; // Fill in the code to read in beverage
  
       switch(beverage)
       {
           case 'a':
           case 'A':
           case 'b':
           case 'B':
           case 'c':
           case 'C':
           case 'd':
           case 'D': validBeverage = true;
           break;
           default: validBeverage = false;
       }

       if (validBeverage)
       {
       cout << "How many cups would you like?" << endl;
       cin >> number; // Fill in the code to read in number
       }

       switch(beverage)
       {
       case 'a':
       case 'A': cost = number * 1.0;
           cout << "The total cost is $ " << cost << endl;
           break;

       case 'b':
       case 'B': cost = number * .75;
           cout << "The total cost is $ " << cost << endl;// Fill in the code to give the case for tea ( $0.75 a cup)
           break;

       case 'c':
           case 'C': cost = number * 1.25;
           cout << "The total cost is $ " << cost << endl;// Fill in the code to give the case for hot chocolate ($1.25 a cup)
           break;

       case 'd':
       case 'D': cost = number * 2.50;
           cout << "The total cost is $ " << cost << endl;// Fill in the code to give the case for cappuccino ($2.50 a cup)
           break;
  
       case 'e':
       case 'E': cout << " Please come again" << endl;
           return 0;
             
       default:cout << "Your selection is not on the list" << endl;// Fill in the code to write a message
  
       cout << "Try again please" << endl;
       }


    }

    while (beverage != 'E' || beverage != 'e')
{
    cin.get();
    return 0;// Fill in the appropriate return statement
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote