int q=coins/25; //gives number of quarters

int mq=coins%25; gives modulo quarters
int md=mq/10;
int mn=md/5;
int mp=mn/1;

printf("%d, %d, %d, %d,", q+md+mn+mp);

So I've been able to prompt the user for a float and convert that float to an int*100. The trouble is with my algorithm - I'm not sure where to go from here.

This code currently prints the number of quarters, plus the modulo's for dimes, nickels, and pennies. My above code allows me to pass all of the check50 inputs above $1 - nothing below, so I imagine I've made all of my variables dependent on the quarter. I was trying to figure out an efficient way to do the same thing with the other coins, but it just seems like too many variables.

I feel like I'm on the right track but another set of eyes would be a big help right now. Any advice is welcome. Thanks so much.

1 Answer 1


No, not really the right track. Think about what you are really doing. First, I'm not sure where you stored the actual value from the float * 100, but I'll guess that it is in coins.

int mq=coins%25; actually gives you the change left after removing all the quarters. int md=mq/10; This is that change divided by 10, but it's an integer divide, so there's no remainder. It will give the number of dimes in the change, but the remainder is abandoned. int mn=md/5; Now it gets bizarre. This is the number of dimes that were counted divided by 5. The logic has gone totally off the rails. int mp=mn/1; Same kind of result as for nickels.

You need to not only calculate the number of quarters, dimes, nickels and pennies, but how much change is still left after removing those coins from the running total, and you need to do that at each stage.

You should rethink the logic, and maybe review the class material for this pset.

If this answers your question, please click the check mark to accept this and remove the question from the unanswered pool. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .