This is my first time posting here so this post might be a little bit of a mess but I'll try my best to explain everything.
I have to make a program that acts kinda like Self-checkout in a store. However i run into two issues when people are inserting money into the machine. People insert money like this: 10 20 50 0.10 .... and the paying ends with 0 or by using ctrl+d. (people can only use coins of this value: 100, 50, 20, 10, 5, 2, 1, 0.50, 0.20, 0.10, 0.05, 0.02 a 0.01 as you can see in the code)
Well when I end the payment with 0 program exits normally.(like this: 50 20 0)
However when I end it with ctrl+d it causes infinite loop and i don't understand why.
And the second issue is that for some reason it won't add numbers like 0.10, 0.20 and so on. Any ideas how to fix this or what might be causing the error?
And dont mind the printf in the middle that was just me checking the value.
float bill,x,payment=0,k=0;
printf("coins ");
while(k==0)
{
scanf("%f", &x);
if(x==0 )
{
goto END;
}
if(x ==100 || x ==50 || x ==20 || x ==10 || x ==5 || x ==2 || x ==1 || x ==0.50 || x==0.10 || x ==0.20 || x ==0.05 || x ==0.02|| x ==0.01 )
{
payment += x;
printf("==============");
printf("%.2f \n",payment);
}
else{
printf("%.2f is invalid",x);
k = 1;
goto END2;
}
}
END:
printf("%.2f \n", payment);
END2:
return 0;