The variable Cost represents how much an item costs and the variable Paid repres
ID: 3542331 • Letter: T
Question
The variable Cost represents how much an item costs and the variable Paid represents the amount
paid for the item. You can assume that Cost and Paid are dollar amounts that can be made
by combining the denominations: 100, 50, 20, 10, 5, 2, and 1. Write code that assigns to a
7-by-1 array Change the fewest number of bills that the seller should give back to the buyer,
in decreasing order (i.e. the rst element of Change would be the number of 100 dollar bills to
return and the last element would be the number of 1 dollar bills to return). You can also assume
that Paid is at least as large as Cost. If Paid and Cost are equal, assign an empty array [] to
the variable Change.
Explanation / Answer
code could beRange Number of coins (in the minimal set) 1 5 10 25 [1,1] 1 [1,2] 2 [1,3] 3 [1,4] 4 [1,5] 5 [1,5]* 4 1 * two solutions here [1,6] 4 1 [1,9] 4 1 [1,10] 5 1 * experience tells us it's not the most viable one :p [1,10] 4 2 * not so viable either [1,10] 4 1 1 [1,11] 4 1 1 [1,19] 4 1 1 [1,20] 5 1 1 * not viable (in the long run) [1,20] 4 2 1 * not viable (in the long run) [1,20] 4 1 2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.