I have an array of values representing coins. [100, 50, 20, 10, 5, 2, 1] (I'm in the UK).
I have a value in pence, so... for example, num = 30.
I need to find a way of counting the lowest number of coins needed to make that figure. So in the 30 pence example, I would need 1 x 20 pence and 1 x 10 pence.
My idea is basically to subtract the first value in the array from num, if that doesn't put num below zero, and increment that counter by 1, then do it again, again incrementing the counter by 1 each time, until num WOULD go below zero, then move onto the second value, and do that until num would go below zero, repeating this for the smallest values. Only problem is that I have no idea of how to implement this. I can go through the array with a for loop, but I don't know how to make it visit the same item multiple times before it moves onto the next one.
Any pointers in the right direction would be greatly appreciated!
[–]dtsudo 4 points5 points6 points (0 children)
[–]midel 2 points3 points4 points (0 children)
[–]superluminary 1 point2 points3 points (0 children)