Problem 3 – Assume you are a clerk in a store. Explain the process of making cha
ID: 3875925 • Letter: P
Question
Problem 3 – Assume you are a clerk in a store. Explain the process of making change for the customer who gave you some money for their purchase. You should give out the fewest number of coins and bills as possible to give the correct change. To get the amount owed, use https://www.random.org/integers/ but change the range of numbers to 1 to 1000, generate a single value, and divide it by 100. If the random number is 637, the amount owed is $6.37. Assume the customer give you a $20 dollar bill. How do you figure out what change to give the customer? Tell me step by step what you did to get the result in pseudocode?
Explanation / Answer
Looking at the example given in the question, customer gives a $20 bill and owes amount $6.37. The amount to be returned is, x= $20-$6.37 = $13.63.
Now, the largest denomination bill/coin which is smaller than x is $10. hence, the clerk will return 1 $10 bill.
Therefore, x=x-10=3.63.
Now, the largest denomination bill/coin which is smaller than x is $2. hence, the clerk will return 1 $2 bill.
Therefore, x=x-2=1.63.
Now, the largest denomination bill/coin which is smaller than x is $1. hence, the clerk will return 1 $1 bill.
Therefore, x=x-1=0.63.
Now, the largest denomination bill/coin which is smaller than x is $0.5. hence, the clerk will return 1 $0.5 coin.
Therefore, x=x-0.5=0.13.
Now, the largest denomination bill/coin which is smaller than x is $0.1. hence, the clerk will return 1 $.1 coin.
Therefore, x=x-0.1=0.03.
Now, the largest denomination bill/coin which is smaller than x is $0.01. hence, the clerk will return 3 $0.01 coin.
Therefore, x=x-3*0.01=0.
PSEUDOCODE:
x=20-owed
if(floor(x/10))
{
print("Return ",floor(x/10),"$10 bills")
x=x%10
}
if(floor(x/5))
{
print("Return ",floor(x/5),"$5 bills")
x=x%5
}
if(floor(x/2))
{
print("Return ",floor(x/2),"$2 bills")
x=x%2
}
if(floor(x))
{
print("Return ",floor(x),"$1 bills")
x=x-floor(x)
}
if(floor(x/0.5))
{
print("Return ",floor(x/0.5),"$0.5 coins")
x=x-floor(x/0.5)
}
if(floor(x/0.25))
{
print("Return ",floor(x/0.25),"$0.25 coins")
x=x-floor(x/0.25)
}
if(floor(x/0.1))
{
print("Return ",floor(x/0.1),"$0.1 coins")
x=x-floor(x/0.1)
}
if(floor(x/0.05))
{
print("Return ",floor(x/0.05),"$0.05 coins")
x=x-floor(x/0.05)
}
if(floor(x/0.01))
{
print("Return ",floor(x/0.01),"$0.01 coins")
x=x-floor(x/0.01)
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.