Question
DO NOT use double or float literals or variables for this coding. Write a program that simulates the operation of a vending machine, which only
DO NOT use double or float literals or variables for this coding.
Write a program that simulates the operation of a vending machine, which only dispenses sodas. The price of a soda in this vending machine is $2.50. The user will choose from a menu, money to deposit. As the user chooses money items, they are dropped into the vending machine. The user will stop depositing money items when the number 5 (cancel transaction) is entered, or when the user has deposited enough money to pay for a soda.
After the selection phase has ended, the program should do one of the following:
-
If the user has paid exactly the correct amount, it should say "Dispensing soda."
-
If the user paid too much, it should say "Dispensing soda." Then it should print to the screen the amount of change owed, and finally print a list of money items that it will be dispensing. This list should be the least amount of money items needed to add up to the change that is owed.
-
If the user cancelled the transaction, it should say "Transaction cancelled."
-
If the user had actually deposited any money items, the program should say "Returning:" and then print a list of money items to be returned. The list will be the same money items that were deposited, and in the same order they were deposited.
-
#include
// generate an enumeration data type called Money enum class Money { nickel = 5, dime = 10, quarter = 25, dollar = 100 };
const int MAXSIZE = 50; const int PRICE = 250;
// price format: $X.XX // price in pennies
void PrintPrice(int price);
// Takes user input (1, 2, 3, 4) and converts it to a Money type Money ConvertToMoney(int x);
// Prints a word to the screen stating what the Money type is void PrintMoney(Money x);
// Prints the coins to dispense, which add up to amount // Note: This will never need to dispense a dollar void DispenseChange(int amount);
int main() { // generate main program code
cout << endl; return 0; }
void PrintPrice(int price) { // generate code for the printPrice function }
void DispenseChange(int amount) { // generate code for the DispenseChange function }
Money ConvertToMoney(int x) { // generate code for the ConvertToMoney function
return Money::dollar; }
void PrintMoney(Money x) { // generate code for the PrintMoney function }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started