<p>Part 1</p> <p>Find the most efficient way of making change for any amount of
ID: 3621235 • Letter: #
Question
<p>Part 1</p><p>Find the most efficient way of making change for any amount of money up to $200.00. The most effiecent way means the fewest pieces of currency. The follow are the values of monies to use.</p>
<p>$100.00 50.00 20.00 10.00 5.00 2.00 1.00 0.50 0.25 0.10 0.05 0.01</p>
<p>For example, if I were to give you change of $8.93, the most efficient would be 1- $5.00 1- $2.00 1-  $1.00</p>
<p>1-  $0.50  1- 0.25 1-0.10 1-0.05 and 3- 0.01. (Only tell the change I would get, not what will not get(e.g. 0 -5.00 0-2.00 0-1.00, etc.)</p>
<p>Part 2</p>
<p>The harder part, if the amount of change is $10.00 or less, I want you to tell me the number of different ways you could have made change for that amount. For example, if my change was $0.25,you would give me a quarter, but tell me that there are 13 different ways, you could have made( or if my change was 0$0.50, you would give me a half-dollar and tell me there are 50 ways you could have made change. In which the system would calculate and display all the possiblitys of $0.50) </p>
Explanation / Answer
Part 1 is easy make different variables for each currency make a loop for each variable and test to see if subtracting that from the needed change goes below 0, if so, subtract that amount and add 1 to the needed variable. You don't even need to write loops for all the amounts (though you could), a simple if statement would word. Example, You would never give out 2 fifty dollar bills as a hundred would be given out first, so 1 check is all you need. Same with 10s, you would never give out more then one 10 dollar bill as you could give a 20 instead while(changeNeeded >= 100){ changeNeeded = changeNeeded - 100; hundredDollarBills++; } if(changeNeeded >= 50){ changeNeeded = changeNeeded - 50; fiftyDollarBills++; } write for each currency amount then print bill amount that is > 0 example if (twentyDollarBills > 0){ print("the amount of twenties needed is: " + twentyDollarBills) } part 2 to calculate the change needed, think of each as the amount of pennies needed. and have functions call the lower denominations i.e. a 10 dollar bill is 1000 pennies. int p(int n) { return 1; } int n(int x) { if (x >= 0) return n(x-5) + p(x); return 0; } int d(int x) { if (x >= 0) return d(x-10) + n(x); return 0; } int q(int x) { if (x >= 0) return q(x-25) + d(x); return 0; } int h(int x) { if (x >= 0) return h(x-50) + q(x); return 0; } int o(int x) { if (x >= 0) return c(x-100) + h(x); return 0; } int f(int x) { if (x >= 0) return f(x-100) + o(x); return 0; } int t(int x) { if (x >= 0) return t(x-100) + f(x); return 0; } have your main function call t, should work
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.