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?