Question: Using Matlab || Using Matlab || Using Matlab m5. In purchases paid in cash, the seller must return money that was overpaid. This is commonly

Using Matlab || Using Matlab || Using Matlab

Using Matlab || Using Matlab || Using Matlab m5. In purchases paid

m5. In purchases paid in cash, the seller must return money that was overpaid. This is commonly referred to as "giving change." The bills and coins required to properly give change can be defined by a recursive relationship. If the amount paid is more than $100 more than the cost, then return a hundred-dollar bill along with the result of a recursive call to the change func- tion with $100 subtracted from the amount paid. If the amount paid is more than $50 over the cost of the item, then return a fifty-dollar bill, along with the result of a recursive call to the change function with $50 subtracted. Similar clauses can be given for every denom- ination of US currency. The denominations of US currency, in dollars, is 100, 50, 20, 10, 5, 1, 0.25, 0.10, 0.05, and 0.01. For this problem we will ignore the two-dollar bill, which is not in common circulation. You may assume that cost and paid are scalars, and that paid >= cost. The output variable, change, must be a column vector as shown in the test case. Use recursion to program a function with header [ change] myChange(cost, paid) where cost is the cost of the item, paid is the amount paid, and change is an array con- taining the list of bills and coins that should be returned to the seller. Note: Watch out for the base case

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!