Question: Soda Machine simulator Write a program that simulates a soda machine. Implement this program in a file called soda.cpp . The program should work as

Soda Machine simulator
Write a program that simulates a soda machine. Implement this program in a file called soda.cpp. The program should work as follows:
a. The program should define a structure named Soda that contains the following attributes:
i. Soda name
ii. Soda cost
iii. Quantity available
b. The program should initialize an array of five Soda structures with the following data in order:
\table[[Soda name,Cost,Quantity],[Cola,$1.50,30],[Root Beer,$1.40,20],[Orange Soda,$1.65,25],[Seltzer Water,$0.95,1],[Ginger Ale,$2.05,15]]
c. Before receiving user input, the program should display a menu detailing the available drinks (numbered 1-5), their costs (in dollar format), and quantity in a left-aligned fashion.
d. The user should be able to select a drink (1-5) or quit (6)
i. If the user enters an invalid menu selection, an appropriate error message should be displayed and they should be re-prompted for another selection.
ii. If the user selects a drink that is out of stock, an out-of-stock message should be displayed and they should be re-prompted for another selection.
e. After selecting a drink, the user should be able to input the amount of money they want to insert to pay. This machine only accepts non-zero values less than or equal to $5.
i. If the user enters an invalid money amount, an appropriate error message should be displayed and they should be re-prompted for a valid amount.
ii. If the user enters a money amount less than the cost of the drink selected, an insufficient-funds message should be displayed and they should be re-prompted for a valid amount.
iii. If the user enters a valid money amount, the quantity of the selected drink should be decremented and the leftover change should be displayed in dollar format.
f. When the user quits, the program should display the total revenue earned by the soda machine in dollar format.
Example run 1(underlined portions correspond to user input):
\table[[1) Cola,$1.50,Qty: 30],[2) Root Beer,$1.40,Qty: 20],[3) Orange Soda,$1.65,Qty: 25],[4) Seltzer Water,$0.95,Qty: 1],[5) Ginger Ale,$2.05,Qty: 15]]
Select a soda or 6 to quit: 2
Invalid selection, please try again: 1
Enter money to insert: 10.00
This machine only accepts $5.00 or less
Enter money to insert: -2.00?
Please enter a positive, non-zero dollar amount
Enter money to insert: 2.00
Change: $0.50
\table[[1) Cola,$1.50,Qty: 29],[2) Root Beer,$1.40,Qty: 20],[3) Orange Soda,$1.65,Qty: 25],[4) Seltzer Water,$0.95,Qty: 1],[5) Ginger Ale,$2.05,Qty: 15]]
Select a soda or 6 to quit: 4
Enter money to insert: 0.50?
Insufficient funds
Enter money to insert: 1.00
Change: $0.05
\table[[1) Cola,$1.50,Qty: 29],[2) Root Beer,$1.40,Qty: 20],[3) Orange Soda,$1.65,Qty: 25],[4) Seltzer Water,$0.95,Qty: 0],[5) Ginger Ale,$2.05,Qty: 15]]
Select a soda or 6 to quit: 4
Seltzer Water is out of stock.
Select a soda or 6 to quit: 3?
Enter money to insert: 5.00?
Change: $3.35
\table[[1) Cola,$1.50,Qty: 29],[2) Root Beer,$1.40,Qty: 20],[3) Orange Soda,$1.65,Qty: 24],[4) Seltzer Water,$0.95,Qty: 0],[5) Ginger Ale,$2.05,Oty: 1.5]]
Soda Machine simulator Write a program that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!