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

C++- Homework 9 (Drink Machine Simulator) Write a program that simulates a soft

ID: 3719968 • Letter: C

Question

C++- Homework 9 (Drink Machine Simulator) Write a program that simulates a soft drink machine The program should use a structure that stores the following data » Drink nam 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 0.85 0.75 0.90 0.80 0.80 Number in Machine 20 20 20 20 20 Cola Root Beer Lemon-Lime Grape Soda Cream Soda 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 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 is should display the total amount of money the machine entered and which drink is sold out. Input Validation: When the user enters an amount of money, do not accept a negative values, or values greater than $1.00

Explanation / Answer

/* if you any doubt , please let me konw in comment section. if this helps you then give your positive feedback*/

#include<iostream>

#include<string>

#include<conio.h>

using namespace std;

struct drink{

       string drink_name;

       float drink_cost;

       int total_drinks;

};

int main()

{

       drink *pointer;

       pointer = new drink[5];

       char ch;

       float amount;

       //=================intitilization==================

       pointer[0].drink_name = "Cola";

       pointer[0].drink_cost = 0.85;

       pointer[0].total_drinks = 20;

       pointer[1].drink_name = "Root Bear";

       pointer[1].drink_cost = 0.75;

       pointer[1].total_drinks = 20;

       pointer[2].drink_name = "Grape Soda";

       pointer[2].drink_cost = 0.80;

       pointer[2].total_drinks = 20;

       pointer[3].drink_name = "Cream Soda";

       pointer[3].drink_cost = 0.80;

       pointer[3].total_drinks = 20;

pointer[4].drink_name="Lemon Lime";

pointer[4].drink_cost = 0.9;

pointer[4].total_drinks = 20;

       //====================================================

       do{

              cout << " =================AVAILABLE DRINKS==================";

              cout << " 1. Cola 2. Root Bear 3. Grape Soda 4. Cream Soda 5.Lemon Lime";

              cout << " press specific number to take drink or '6' to Quit ";

              ch = getche();

              if(ch == '1')                        //first drink

              {

                     cout << " Give Price :";

                     cin >> amount;

                     if(amount > 0 || amount < 1.00)

                     {

                     }

                     else

                     {

                           cout << "Wrong Input...";

                           exit(0);

                     }

                     float remaining = amount - pointer[0].drink_cost;

                     cout << " Returned Money : " << remaining;

                     (pointer[0].total_drinks)--;

                     if(pointer[0].total_drinks == 0)

                           cout << " These drinks has been ended...";

              }

              else if(ch == '2')                   //second drink

              {

                     cout << " Give Price :";

                     cin >> amount;

                     if(amount > 0 || amount < 1.00)

                          

                     {

                     }

                     else

                     {

                           cout << "Wrong Input...";

                           exit(0);

                     }

                     float remaining = amount - pointer[1].drink_cost;

                     cout << " Returned Money : " << remaining;

                     (pointer[1].total_drinks)--;

                     if(pointer[1].total_drinks == 0)

                           cout << " These drinks has been ended...";

              }

              else if(ch == '3')                     //third drink

              {

                     cout << " Give Price :";

                     cin >> amount;

                     if(amount > 0 || amount < 1.00)

                     {

                     }

                     else

                     {

                           cout << "Wrong Input...";

                           exit(0);

                     }

                     float remaining = amount - pointer[2].drink_cost;

                     cout << " Returned Money : " << remaining;

                     (pointer[2].total_drinks)--;

                     if(pointer[2].total_drinks == 0)

                           cout << " These drinks has been ended...";

              }

              else if(ch == '4')                   //fourth drink

              {

                     cout << " Give Price :";

                     cin >> amount;

                     if(amount > 0 || amount < 1.00)

                     {

                     }

                     else

                     {

                           cout << "Wrong Input...";

                           exit(0);

                     }

                     float remaining = amount - pointer[3].drink_cost;

                     cout << " Returned Money : " << remaining;

                     (pointer[3].total_drinks)--;

                     if(pointer[3].total_drinks == 0)

                           cout << " These drinks has been ended...";

              }

  else if(ch == '5')                     //fifth drink
              {
                     cout << " Give Price :";
                     cin >> amount;
                     if(amount > 0 || amount < 1.00)
                     {
                     }
                     else
                     {
                           cout << "Wrong Input...";
                           exit(0);
                     }
                     float remaining = amount - pointer[2].drink_cost;
                     cout << " Returned Money : " << remaining;
                     (pointer[2].total_drinks)--;
                     if(pointer[2].total_drinks == 0)
                           cout << " These drinks has been ended...";
              }

              else

                     continue;

       }while(ch != '6');

       cout << endl << endl;

       system("pause");

       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