Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Making Change Write a MATLAB function called makechange to determine the minimum number of coins that are needed to make a given amount of change.
Making Change
Write a MATLAB function called makechange to determine the minimum number of coins that are
needed to make a given amount of change. For example, with US currency, the minimum number of
coins to make cents in change is three quarter, dime, and penny Your function should
take two input arguments in this order: the amount of change needed and an array of coin
denominations. For example, for US currency, the amount of change needed must be a whole
number of cents and the array of coin denominations should be Your function should
sort this array in descending order using the sort function with the 'descend' option. Your
function should have one return argument: the number of coins needed. Your function should check
that the inputs are valid. Specifically, your function should verify that the amount of change is non
negative and the array of coin denominations contains at least one value. If the inputs are invalid,
your function should return a value of Also, if it is not possible to make exact change with the
given set of coin denominations, your function should return a value of As one purpose of this
assignment is to provide experience with loops, your code should solve this problem using loops.
Your code should use the following approach:
amount: amount of change to make. Eg
sort coins into descending order
Loop over the array of coins, with being the current coin:
Loop while it possible to deduct from amount:
subtract from amount
increase the coin count by
EndLoop
EndLoop
Note, it is possible to solve this problem more efficiently using integer division tricks such as modulo
and floor, but that would circumvent the purpose of this assignment.
Write a script called runMakechange that calls your makeChange function to compute the
number of US coins needed to make change for every whole number of cents between and
Your script should then graph the number of coins vs the amount of change. Your graph should
include appropriate titles and labels. Save the graph as a png file with the name "change.png
Finally, your script should call your Arraystats function to determine the maximum, minimum,
mean, median, and standard deviation of the coins needed. Print these results to the console with
appropriate formatting to make the output easily understandable.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started