That sounds like a homework problem, so rather than write the code for you, here's a hint -- use another variable, and update it every time you decide how many coins of any specific size you'll use.