I'm working on pset1 Greedy and am trying to use a modulo to eliminate the need for loops. The user inputs a float in the form of the "change" needed. This is converted into a whole number for easier math; then, the number of coins "ncoins" is calculated in integers.
change = round(change*100); ncoins = change / 25; change = change % 25; ncoins = ncoins + (change / 10); change = change % 10; ncoins = ncoins + (change / 5); change = change % 5; ncoins = ncoins + (change / 1);
When I try to compile I get an error for each time modulo is used, saying:
invalid operands to binary expression ('float' and 'float')
I thought that after using round(), all numbers would be treated as integers. Is this incorrect? I have tried typecasting (int) nearly everywhere possible, but still the same error message. Am I simply incorrect in my thinking that my variables will become properly updated at the end of each line? I'm pretty much at a loss here.
Just in case, I have prototyped
float change; int ncoins = 0;