I feel you are overcomplicating this. If you need to write
for(int i = 0; i<change_requested - (((num_quarters * val_quarters) + (num_dimes * val_dimes) + (num_nickles * val_nickles))); i++){
and all this in one line, then something is certainly wrong. You can do this in a much simpler way, by subtracting the value of the coins just calculated from the total amount in order to to obtain the rest:
int vals[] = { 25, 10, 5 };
const char *names[] = { "quarters", "dimes", "nickles" };
int pennies = 100 * GetFloat(); // not good at all, btw (*)
for (int i = 0; i < 3; i++) {
int n = pennies / vals[i];
if (n) {
printf("%d %s ", n, names[i]);
}
pennies -= n * vals[i];
}
if (pennies)
printf("%d pennies", pennies);
printf("\n");
As to why GetFloat()
is not good: floating-point numbers aren't exact, so, for example, 1.26 may be actually represented as something like 1.25999946. When you convert this to an integral value, you may lose a penny or so due to truncation if you are unlucky.