im sort of stuck on this question Write a program that determines the change to
ID: 3591014 • Letter: I
Question
im sort of stuck on this question Write a program that determines the change to be dispensed from a vending machine. An item in the machine can cost between 25 cents and a dollar, in 5 cents increments (25,30,35,40,.......90,95 or 100), and the machine accepts only a single bill to pay for the item. For example, a possible dialogue with the user might be Enter price of the item (from 25 cents to a dollar, in 5-cent increment) : 45 You bought an item for 45 cents and gave me a dollar. So your change is : 2 quarters 0 dimes, and 1 nickel.
Explanation / Answer
First calculate the change suppose you bought items of worth x amount nad given y amount;
change = y - x;
assume change is in cents.
Now create hash of cents and names for all dinominations of coin.
Ex: hash[1] = "cent";
hash[5] = "nickel";
hash[10] = "dime"
....
now start from maximum dinomination of coin and using greedy approach give maximum value coin as much as you can.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.