Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program to work with a vending machine that accepts only a one-dollar bill and returns changes in quarters, dimes, and nickels. Upon

Write a C++ program to work with a vending machine that accepts only a one-dollar bill and returns changes in quarters, dimes, and nickels. Upon startup of this program, the machine is filled with several coins once for each denomination from keyboard input before any purchase (quarters, dimes, and nickels). This vending machine will only accept one-dollar bill and all items cost one dollar or less, but the cost for each item must be a multiple of 5 cents. Your program would read an integer value between 0 and 100 (inclusive), representing the amount of a purchase in cents from a vending machine. Produce an error message if the input value is not in that range or it is not a multiple of 5 cents. If the input is valid, determine the amount of change that would be returned from one dollar, and print the number of quarters, dimes, and nickels. It is important to maximize the coins with the highest value first and utilize the next denomination if the current denomination is exhausted. This strategy will work for most cases, but there are a few cases where it wouldnt work (such as Q = 2, D = 4, N = 0, and you need to give back 55 cents) and you do not have to handle such situations (go ahead and reject such transaction as insufficient coins). Reject a valid purchase if it cannot be processed (not enough available coins to make the change) but program must allow more transactions. The machine must be able to keep track of an accurate count of coins in the machine at all time. Your program must allow purchases to be repeated until a sentinel value of 0 is entered. Print number of valid transactions, dollar bills, the number of coins for each denominations, and current balance just before terminating the program. Follow the format below and you must plan and write down the pseudocode before attempting your code on the computer. In addition to the main function, you must use two more reasonable functions for this project and you should try to utilize more functions, so your program is more readable. You must follow the user-interface as shown below and run those test cases at the minimum: Vending Machine Version 1 by [Your Name] Fill up machine with changes. Please wait ... Enter number of quarters, dimes, and nickels --> 2 4 4

There are 2 quarters, 4 dimes, and 4 nickels.

Initial machine balance is $1.10.

Only one-dollar bill will be accepted.

Only amount between 0 to 100 and multiple of 5 is accepted.

Enter 0 to stop the program.

Machine is now ready. Enter a purchase amount [0 - 100] --> 35

You entered a purchase amount of 35 cents.

Please insert one-dollar bill. Processing your purchase ...

Your change of 65 cents is given as: quarter(s): 2 dime(s): 1 nickel(s): 1

Enter a purchase amount [0 - 100] --> 31

You entered a purchase amount of 31 cents.

Invalid amount (not a multiple 5). Try again. Enter a purchase amount [0 - 100] --> 35

You entered a purchase amount of 35 cents.

Please insert one-dollar bill. Processing your purchase ... Insufficient changes!

Your transaction cannot be processed.

Please take back your dollar bill. Enter a purchase amount [0 - 100] --> 75

You entered a purchase amount of 75 cents. Please insert one-dollar bill.

Processing your purchase ... Your change of 25 cents is given as: quarter(s): 0 dime(s): 2 nickel(s): 1 Enter a purchase amount [0 - 100] --> 105

You entered a purchase amount of 105 cents. Invalid amount (outside valid range). Try again. Enter a purchase amount [0 - 100] --> 0 Final report is being generated ... There are 2 valid transactions.

Number of dollars : 2 Number of quarters: 0 Number of dimes : 1 Number of nickels : 2

Machine balance : $2.20

Machine is shutting down. Good bye.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students also viewed these Databases questions