#include <stdio.h>
#include <math.h>
#include <cs50.h>
int main(void)
{
// Get float for cents
// Take inputs of positive floats and repromt user for negative
float dollars;
do
{
dollars = get_float("Change owed: ");
}
while (dollars < 0);
// divide appropriate amount of cents from change owed
// take the remainder of previous amount & divide w/ new number
int cents;
cents = round(dollars * 100);
int coins = 1;
while (cents >= 25)
{
cents = cents/25;
coins ++;
}
while (cents >= 10)
{
cents %= cents/10;
coins ++;
}
while (cents >= 5)
{
cents %= cents/5;
coins ++;
}
while (cents >= 1)
{
cents %= cents/1;
coins ++;
}
// print result of all coins being added
printf("%i\n", coins);
}
What is wrong with my code? For example, when I type 0.75, ill get a result of 3 coins. When I type in 0.50, ill get the same result of 3 coins. Why is this? How can I fix this problem?