L E S S O N S E T 5 Loops and Files LAB 5.2 Working with the do-while Loop Bring in the program dowhile.cpp from the Lab 5 folder. The code is shown below: // This program displays a hot beverage menu and prompts the user to // make a selection. A switch statement determines which item the user // has chosen. A do-while loop repeats until the user selects item E // from the menu. // PLACE YOUR NAME HERE #include #include using namespace std; int main() { // Fill in the code to define an integer variable called number, // a floating point variable called cost, // 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; continues 68 LESSON SET 5 Loops and Files cout << "Enter the beverage A,B,C, or D you desire" << endl; cout << "Enter E to exit the program" << endl << endl; // 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 == true) { cout << "How many cups would you like?" << endl; // Fill in the code to read in number } // 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; // Fill in the code to give the case for hot chocolate ($1.25 a cup) // Fill in the code to give the case for tea ( $0.75 a cup) // Fill in the code to give the case for cappuccino ($2.50 a cup) case 'e': case 'E': cout << " Please come again" << endl; break; default:cout << // Fill in the code to write a message // indicating an invalid selection. cout << " Try again please" << endl; } } // Fill in the code to finish the do-while statement with the // condition that beverage does not equal E or e. // Fill in the appropriate return statement } Lesson 5A 69 L E S S O N 5 B Exercise 1: Fill in the indicated code to complete the above program. Then compile and run the program several times with various inputs. Try all the possible relevant cases and record your results. Exercise 2: What do you think will happen if you do not enter A, B, C, D or E? Try running the program and inputting another letter. Exercise 3: Replace the line if (validBeverage == true) with the line if (validBeverage) and run the program again. Are there any differences in the execution of the program? Why or why not?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

L E S S O N S E T
5 Loops and Files

LAB 5.2 Working with the do-while Loop
Bring in the program dowhile.cpp from the Lab 5 folder. The code is shown
below:
// This program displays a hot beverage menu and prompts the user to
// make a selection. A switch statement determines which item the user
// has chosen. A do-while loop repeats until the user selects item E
// from the menu.
// PLACE YOUR NAME HERE
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Fill in the code to define an integer variable called number,
// a floating point variable called cost,
// 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;
continues
68 LESSON SET 5 Loops and Files
cout << "Enter the beverage A,B,C, or D you desire" << endl;
cout << "Enter E to exit the program" << endl << endl;
// 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 == true)
{
cout << "How many cups would you like?" << endl;
// Fill in the code to read in number
}
// 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;
// Fill in the code to give the case for hot chocolate ($1.25 a cup)
// Fill in the code to give the case for tea ( $0.75 a cup)
// Fill in the code to give the case for cappuccino ($2.50 a cup)
case 'e':
case 'E': cout << " Please come again" << endl;
break;
default:cout << // Fill in the code to write a message
// indicating an invalid selection.
cout << " Try again please" << endl;
}
} // Fill in the code to finish the do-while statement with the
// condition that beverage does not equal E or e.
// Fill in the appropriate return statement
}
Lesson 5A 69
L E S S O N 5 B
Exercise 1: Fill in the indicated code to complete the above program. Then
compile and run the program several times with various inputs. Try all the
possible relevant cases and record your results.
Exercise 2: What do you think will happen if you do not enter A, B, C, D
or E? Try running the program and inputting another letter.
Exercise 3: Replace the line
if (validBeverage == true)
with the line
if (validBeverage)
and run the program again. Are there any differences in the execution of
the program? Why or why not?

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Graphical User Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education