I get the correct answer for some values, i get the wrong answer for others. I didn't convert my change to cents because I figured I could just keep all my cents, dimes, quarters in decimal values too. I think my issue arises when the value equals one of the conditions in the loops and then the coin value won't increase. Anyone can tell me what's wrong with this code ?
#include <cs50.h>
#include <stdio.h>
int main(void)
{
float change;
do
{
change = get_float("change owed = ");
} while (change < 0);
int coins = 0;
while (change >= 0.25)
{
coins ++;
change = change - 0.25;
}
while (change >= 0.10)
{
coins ++;
change = change - 0.10;
}
while (change >= 0.05)
{
coins ++;
change = change - 0.05;
}
while (change >= 0.01)
{
coins ++;
change = change - 0.01;
}
printf ("%i\n", coins);
}