So I built this for CS50 (great course so far) but I'm not sure why the only error I've hit 1-100 cents is 53, which it gives as only 4 coins instead of the correct 5. I'm new to C and would love a second pair of eyes to see my mistake.
//Implement a program that calculates the minimum number of coins required to give a user change.
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void)
{
//get change owed, reject if negative
float cash;
printf("Change owed: ");
do {
cash= get_float();
}
while(cash<0);
//avoid imprecision by converting to cents
int cents = cash*100;
int count = 0;
//while(cash>1){
// cash-1;
// count++;
//}
while (cents>=25){
count++;
cents-=25;
}
while (cents>=10){
count++;
cents-=10;
}
while (cents>=5){
count++;
cents-=5;
}
while (cents>=1){
count++;
cents-=1;
}
printf("%i\n", count);
}