Q:

Problems with subtraction of a float number

This program have to count minimum number of coins, but it has some kind of bug because results are weird. It`s probably obvious mistake but I cant find it.
int main(int argc,char* argv[]){
      float x;
      printf("How much cash in float number:");
      scanf("%f", &x);

      int quaters;
      while(x>=0.25){
        x-=0.25;
        quaters++;
      }
      printf("%f\n",x);

      int fives;
      while (x>=0.05){
        x-=0.05;
        fives++;
      }
       printf("%f\n",x);

      int one;
      while (x>=0.01){
        x-=0.01;
        one++;
      }
       printf("%f\n",x);
      printf("quaters %d\t fives %d\t ones %d\n", quaters, fives, one);
      return 0;
    }

And the output is this
    How much cash in float number:0.41
0.160000
0.010000
0.010000
quaters 1    fives 3     ones 32764

What`s wrong?

A:

You need to initialize quaters, fives and one to 0 before using it:
int quaters=0;
....
int fives=0;
....
int one=0;
....

Regarding the last 0.01 result, google for "comparing float variables C++". Even here in SO you will find plenty of related posts.
For immediate solution, since you use up to 2 digits after the decimal point, change float compare from
x>=0.25

to
x>0.249

And all the others accordingly:
x>0.049

x>0.009

