I'm encountering some problem with my code with regards to pset1 Greedy! For some odd reason my code can't seem to compute pennies? So whenever i put in any values that has a 0.01 it won't calculate it in.
Is there anything fundamentally wrong with my code? I tried changing the condition for the part that calculates the pennies but can't seem to get it right...
Any help would be greatly appreciated!!
if (change > 0.0)
{
// Checking how many quarters to return in change
for (float i = change; i >= 0.25; i = i - 0.25)
{
coins++;
change = change - 0.25;
}
// Checking how many dimes to return in change
for (float i = change; i >= 0.10; i = i - 0.10)
{
coins++;
change = change - 0.10;
}
// Checking how many nickels to return in change
for (float i = change; i >= 0.05; i = i - 0.05)
{
coins++;
change = change - 0.05;
}
// Checking how many pennies to return in change
for (float i = change; i >= 0.01; i = i - 0.01)
{
coins++;
change = change - 0.01;
}
// letting the user know how many coins is needed in change
printf("%d\n", coins);