You could, Let's simplify it by numbering the sweet types (1 is chews, 2 is mini eggs etc). So you have 4 types.
Then the total amount of money: 20.
Next, you need to know the combinations of sweets he can buy. So he could buy 8 chews, or 7 chews + 1 egg, or 6 chews, 1 egg and 1 lollipop and so on. You need to get it to loop over all the possibilities (I'll come to that in a second) and for each one, figure out the cost. If the cost is 20, then you have found a valid option, so print it out.
So, looping over the options (hopefully you understand for loops)
For(sweet1 type = 1 up to 4) {
For(sweet2 type = 1 up to 4) {
.... you'll have 8 for loops in total, for sweet 1 up to sweet 8...
For(sweet8 type = 1 up to 4) {
Calculate the total cost of sweet1 + sweet2 + ... + sweet8
If the cost is exactly 20, print out this result
}
}
}
This would print you out all the valid combinations, in this format: 1, 3, 3, 1, 2, 2, 2, 2. You could make it prettier by getting it to print out the names of the sweets instead of "1","2" etc. It will also print out duplicates, and take a long time to run - it can be made more efficient though (I'm too tired to work it out now).
And you could go really fancy and combine the types so it says "2 chews, 3 lollipops and 3 mini eggs", for example.