I apologize if this question has been asked before. I looked around and was not able to find a solution, I am new to C.
I understand that I am not able to get a % from a float. How would I be able to capture the remainder of this math, if I am using 2 floats?
** Always use the largest coin possible
** keep track of coins used
** Print the final amount of coins
int main (void)
int counter = 0;
float quarter = 0.25;
//float quarter = 0.25, dime = 0.10, nickel = 0.05, penny = 0.01;
/* Prompt user for an amont of change*/
printf("How much do we owe you in change? ");
change = GetFloat();
while (change <= 0);
if (change >= quarter)
division = (change / quarter);
counter += division;
//change = (int)(change % quarter);
printf("change: %.2f\n", change);
printf("counter: %d\n ", counter);
You may want to check fmod.
You can also do something like
change = change - (int)(change / quarter) * quarter