Write a program that simulates a soft drink machine.The program should use a str
ID: 3654887 • Letter: W
Question
Write a program that simulates a soft drink machine.The program should use a structure that stores the following data: Drink Name Drink Cost Number of Drinks in Machine The program should create an array of five structures. the elements should be initialized with the following data: Drink Name cost # in Machine Cola . 75 20 Root Beer .75 20 Lemon-Lime .75 20 Grape Soda .80 20 Cream Soda .80 20 Each 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 either quit the program or pick a 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 has sold out, a message should be displayed. The loop then repeats. When the user choose to 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.Explanation / Answer
#include #include #include using namespace std; struct drink{ string name; double cost; int quantity; }; int main(){ drink Machine[5]; string Name[5]={"Cola","Root Beer", "Lemon-Lime","Grape Soda","Cream Soda"}; double Cost[5]={.75, .75 ,.75 ,.80,.80}; int Q[5]={20,20,20,20,20}; int i,choice; double balance,paid,moneyEarned=0; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.