You want to work from the highest coin you have to the lowest.
How many 2s in “giveback”? Take 2* that number off giveback, then calculate how many 1s are left in “giveback”. Then how many 0.5s, and so on until the end.
For example:
Giveback = 8.57
4 * 2 euro coins in 8. You can find this by dividing giveback by 2 (4.285) and then rounding down to the nearest whole number (4).
8.57 – (4*2) = 0.57.
0 * 1 euro coins in 0.57
1 * 0.5 coins in 0.57, remaining 0.07
And so on.
I don’t want to give you the code, else you can copy/paste in to your assignment, but this logic should help.
4
solved C# : Returning how many coins of what kind should be returned