Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(I NEED C++ CODE)Write a program that simulates a soft drink machine. The program should use a structure named Drink that contains the following information:

(I NEED C++ CODE)Write a program that simulates a soft drink machine. The program should use a structure named Drink that contains the following information:

the drink name

the drink cost

the number of drinks in the machine

The program should then create an array of 5 Drink structures. The elements should be initialized with the following data.

Drink Name

Cost

Number in Machine

Cola

.65

20

Root Beer

.70

20

Lemon-Lime

.75

20

Grape Soda

.85

20

Water

.90

20

Every time the program runs it should enter a loop that performs the following steps. A list of drinks is displayed on the screen. The user should be allowed to quit the program or select a drink. You can have the user select a drink any way you want. One way would be to have the menu display with a number next to each drink.

If the user selects a drink, he or she will next enter the amount of money that is to be inserted into the drink machine. The program should display the amount of change that would be returned and subtract one from the number of that drink left in the machine. If the user selects a drink that is sold out a message should be displayed. The loop then repeats asking the user if they want to quit or select another drink. When the user choose the quit the program it should display the total amount of money the machine earned.

Input Validation: When the user enters an amount of money do not accept negative values or values greater than $1.00.

OUTPUT SHOULD BE LIKE THIS

SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Invalid selection. Please try again. SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Invalid selection. Please try again. SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: Please enter an amount between $0.00 and $1.00. It should also be equal to or greater than the drink price : CHANGE : $0.35 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.15 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.30 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.05 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: Please enter an amount between $0.00 and $1.00. It should also be equal to or greater than the drink price : CHANGE : $0.05 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: SOFT DRINK MACHINE REPORT -------------------------- Total amount earned: $4.50 

part 2

SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Sorry. This drink is sold out. SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Sorry. This drink is sold out. SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Sorry. This drink is sold out. SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Sorry. This drink is sold out. SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Sorry. This drink is sold out. SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Sorry. This drink is sold out. SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.30 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: Please enter the amount you want to insert: CHANGE : $0.25 SOFT DRINK MACHINE ------------------ 1) Cola ($0.65) 2) Root Beer ($0.70) 3) Lemon-Lime ($0.75) 4) Grape Soda ($0.85) 5) Water ($0.90) 6) Quit Program Please make a selection: SOFT DRINK MACHINE REPORT -------------------------- Total amount earned: $14.45 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How can you defend against SQL injection attacks?

Answered: 1 week ago