Swap the loop order: amount in outer loop, coins in inner loop. Now you count permutations instead of combinations. For amount with coins : combinations are , ( ways).
Permutations are , , ( ways). Why does loop order matter? Coins-first keeps you never use a smaller coin after a larger one (avoiding after counting ). Amount-first allows any order. Try both orders on coins and amount . You should get combinations but more permutations.