The following code in my Greedy program (getting float from user simplified for forum purposes!):
change = GetFloat();
// convert to int
int cInt = round(change*100);
// define arraw with values of coins
int coinTypes[4] = {25, 10, 5, 1};
int coinTypeAmt = sizeof(coinTypes)/sizeof(int);
for (int i = 0; i < coinTypeAmt; i++)
{
int remainder = cInt % coinTypes[i];
printf(" remainder: %d\n", remainder);
}
Why will remainder be always wrong for the first value (25) if I input a value smaller than 0.25 cents in the prompt?
0.15 for example will give me a remainder of 15
0.03 - remainder will be 3
0.02 - remainder will be 2
Now that I write this, I realize the remainder is always the same as cInt
if cInt
is smaller than 25.
Any other values seem to work fine...
Why is that??
Thanks! Best, Daniel