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

Notes: Topic is: Abstract Data Structures language is C++ should not include .tx

ID: 665165 • Letter: N

Question

Notes:

Topic is: Abstract Data Structures

language is C++

should not include .txt file

Please explain the steps with comment

13. Drink Machine Simulator 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 Programming Challenges 655 The program should create an array of five structures. The elements should be initialized with the following data: Drink Name Cost Cola .75 Root Beer .75 Lemon-Lime .75 Grape Soda.80 Cream Soda.80 Number in Machine 20 20 20 20 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 chooses 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 S1.00

Explanation / Answer

working c++ code. I have only coded for coke part replicate the same for others

#include <iostream>
#include <string>
#include <cmath>
using namespace std;

struct Machine
{
string Drink_name;
float cost;
int num_drinks;
};
struct Machine drink[] = {{"coke", .75, 20}, {"rootbear", .75, 20}, { "lemon lime", .75, 20},
{"grape soda", .75, 20}, {"cream soda", .80, 20}};
int main()
{
int menu_choice;
float moneyin;
float moneyout;
float temp;
while (menu_choice != 6)
{
cout <<"which drink would you like to buy:" << endl;
cout <<"1-coke" << endl;
cout <<"2-root bear" << endl;
cout <<"3-lemon lime" << endl;
cout <<"4-grape soda" << endl;
cout <<"5-cream soda" << endl;
cout <<"6-Quit " << endl;
cin >> menu_choice;
if (menu_choice == 1)
{
cout << "enter money to inserted into machine between 0 and $1.00" << endl;
cin >> moneyin;
if ((moneyin > 1) || (moneyin < 0))
{
   cout<<"Please enter value in between 0 and 1"<<endl;
   cout<<"reenter your menu choice"<<endl;
   cin>>moneyin;
}
if (moneyin < drink[0].cost)
{
cout<<"money entered is less to buy drink";
}
else
{
if (moneyin == drink[0].cost)
{
cout <<"great" << endl;
drink[0].num_drinks--;
cout<<"current remaining coke is"<<endl;
cout<<drink[0].num_drinks;
}
if (moneyin > drink[0].cost)
{
  
cout <<" your change is:" << (moneyin - drink[0].cost) << endl;
drink[0].num_drinks--;
cout<<"current remaining coke is"<<endl;
cout<<drink[0].num_drinks;
}
}
}
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote