i´ve been trying to figure out what is wrong with my code for the pset1 cash or greedy program, i know about float imprecision but when i print the last value for "ch" it prints .01000, thus meaning that it should actually run one more time adding the missing penny, but i must be missing something... Help!
Here's my code:
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int quarter = 0, dime = 0, nickel = 0, penny = 0, coin = 0;
float ch = get_float("Change Owed: $");
for (quarter = 0; ch >= .25; coin++)
{
quarter++;
ch = ch - .25;
}
for (dime = 0; ch >= .10; coin++)
{
dime++;
ch = ch - .10;
}
for (nickel = 0; ch >= .05; coin++)
{
nickel++;
ch = ch - .05;
}
for (penny = 0; ch >= .01; coin++)
{
penny++;
ch = ch - .01;
}
printf("%i\n", coin);
}