I need help creating a code to calculate monetary change

What is the code to determine how to give change in the correct amount of bills and coins, minimizing the total number of items returned. With the amounts of money owed and given must be variable and based on user input.

댓글 수: 3

This sounds like homework. What have you tried so far?
You can find guidelines for posting homework on this forum here. If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).
bill = 1 + (200-1) .* rand(1,1)
bill = round(bill,2)
pay = input("How much cash did the customer give you?")
change = pay-bill
This is what I have so far, its really simple and it calculates the change but I'm not sure where to start when determining how many bills and coins? Would that need some kind of a conditional statement, with If, and when, etc?
The difficulty of minimizing the number of coins returned depends upon the list of values of the coins.
The UK monetary system uses denominators that are 10^N times {1, 2, 5} -- so for example, 1 pence, 2 pence, 5 pence, 10 pence, 20 pence, 50 pence, and so on. That system allows you to use the "greedy" algorithm.
The US monetary system, which has 1 cent, 5 cent, 10 cent, 25 cent, 50 cent (seldom seen), and $1 . The "greedy" algorithm does not work with US coins.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 9월 21일

댓글:

2021년 9월 21일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by