This solution is outdated. To rescore this solution, sign in.
-
2 Comments
I get the right answer for this using this code....
---
function b = makingChange(a)
change = [100 50 20 10 5 2 1 0.5 0.25 0.1 0.05 0.01];
for i = 1:(length(change)-1)
b(i) = floor(a/change(i));
a = a - b(i)*change(i);
end
b(12) = a/change(12);
end
---
But it tells me I'm getting them all wrong. Not sure why.
Joe, I think you have a floating point rounding error. I had this same issue and its frustrating. If you look at the value for b(12) and what it outputs, it outputs 0.99999. While we know that's correct the computer doesn't. If you just add something at the end of the loop or on the line of b(12)=round(a/change(12), 2) this will round it to the nearest whole number and should get you the answer you're looking for.
Suggested Problems
-
22344 Solvers
-
Back to basics 22 - Rotate a matrix
913 Solvers
-
626 Solvers
-
5516 Solvers
-
1406 Solvers
More from this Author96
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!