# pset1 Greedy doesn't work properly

So I have been working on greedy, but it seems to not work properly. When I run this:

``````{
int x = 0;

float f;
do{
printf("How much?");
f= GetFloat();
float roundf(float f);
}
while(f<0);

for(float i_1= f;1<=i_1; i_1--)
{
x++;
f--;
}
for(float i_2 = f;0.50<=i_2; i_2--)
{
x++;
f=f-0.5;
}
for(float i_3 = f;0.25<=i_3; i_3--)
{
x++;
f=f-0.25;
}
for(float i_4 = f;0.10<=i_4; i_4--)
{
x++;
f=f-0.10;
}
for(float i_5 = f;0.01<=i_5; i_5--)
{
x++;
f=f-0.01;
}
printf("I owe you %i coins", x);
}
``````

I am using Turkish coins, there are 5 different types of Turkish coins and they have values as listed in the code, but my program seems to not count the coins that are worth 0.01 Liras. Here is what it looks like

``````jharvard@appliance (~/pset1): ./greedy
How much?4.59
I owe you 6 coins
sjharvard@appliance (~/pset1): ./greedy
How much?4.60
I owe you 6 coins
sjharvard@appliance (~/pset1): ./greedy
How much?4.50
I owe you 5 coins
``````

Now, when you have this and do a test like `if (x >= 4.200)`, it would be false because x would be less than 4.2, although it is only by 0.00000000000xxx (or whatever the actual number). You might think the number is 4.2, but the computer says it is smaller when it does the comparison.
• I see, although only way around this problem i see is changing for example `for(float i_5 = f;0.01<=i_5; i_5--)` to `for(float i_5 = f;0.009<=i_5; i_5--)` since the difference is after many zeroes. But i think there should be some better way of doing it, this seems kind of cheeky. Thanks for your help Apr 18 '16 at 20:16