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

this question is related to C++. You are going to build a simulator for a vendin

ID: 3763037 • Letter: T

Question

this question is related to C++. You are going to build a simulator for a vending machine. The machine holds 8 different items: Candy Bar $0.60 Energy Bar $1.85 Energy Drink $1.70 Hard Candy $0.90 Popcorn $0.75 Potato Chips $1.10 Soda $1.45 Water $1.25 You need to: 1) Have a function that displays all the items and their prices, prompts the user to enter their choice. Use a sentinel value to “Cancel” the order. 2) In another function, prompt the user to enter the amount of money needed in nickels, dimes, quarters, and dollar bills. So, something costing $0.60 could be 12 nickels, 6 dimes, 2 quarters and one dime, 2 quarters and two nickels, etc. While the amount entered is less than the amount needed, the user should be prompted for the amount still needed. So for $0.60, if the user first enters a quarter, then you should say something like: Please enter $0.35 cents. If they enter too much (i.e. they use 3 quarters), then you will need to give them back a dime and a nickel change. 3) Keep track of how many of each item has been sold, at the end of the program print a table of the items sold like this: Candy Bar 3 Energy Bar 5 Energy Drink 2 Etc. 4) At the end of the program, total the amount of money put into the machine. 5) At the end of the program, write a text file of the items sold, and the total (i.e. all of 3 and 4 into a text file.)

Explanation / Answer

#include <iostream>
#include <string>
#include "Drink.h"
using namespace std;
int main()
{
Drink vending;
int choice,loopChoice;
double moneyBack;
const int DRINKS = 5; Drink data[DRINKS] = {Drink("Coke", .75, 20),Drink("Root Beet", .75, 20),Drink("Orange Soda", .75, 20),Drink("Grape Soda", .75, 20),Drink("Bottled Water", 1.00, 20)};
cout << "To use the vending machine enter 1. "<< "Otherwise, enter 0 to quit. ";
cin >> loopChoice;
while (loopChoice != 0)
{
choice = vending.displayChoices();
moneyBack = vending.buyDrink(choice);
switch (choice)
{
case 1:
if (data[0].count > 0)
data[0].count = vending.dailyReport(moneyBack, data[0].count);
cout << data[0].name << endl << data[0].cost << endl << data[0].count << endl;
break;
case 2:
if (data[1].count > 0)
data[1].count = vending.dailyReport(moneyBack, data[1].count);
cout << data[1].name << endl << data[1].cost << endl << data[1].count << endl;
break;
case 3:
if (data[2].count > 0)
data[2].count = vending.dailyReport(moneyBack, data[2].count);
cout << data[2].name << endl << data[2].cost << endl << data[2].count << endl;
break;
case 4:
if (data[3].count > 0)data[3].count = vending.dailyReport(moneyBack, data[3].count);
cout << data[3].name << endl << data[3].cost << endl << data[3].count << endl;
break;
case 5:
if (data[4].count > 0)
data[4].count = vending.dailyReport(moneyBack, data[4].count);
cout << data[4].name << endl << data[4].cost << endl << data[4].count << endl;
break;
default:
break;
}
cout << "If you would like to make another purchase"<< " enter 1 to continue or 0 to quit. ";
cin >> loopChoice;
}
return 0;
}