That is because with floating point numbers , you can not test for equality. Floating point numbers are an approximations of a given fraction , for example just like you can not store the full decimal representation of 1/7 = 0.14285714.. , this is recurring after simply 6 digits but with another fraction say 1/983 , it has 982 recurring digits !!! , We can only approximately save it to say 8 digits 1/983 ~ 0.00101729 , It is close but not exactly 1/983.
Similarly 1/5 or 0.20 can not be stored in binary exactly but a very close approximation could be stored. Floating point rules of thumbNever use or depend upon equality You can however check if two numbers are close enough. When you can , avoid using floating point numbers
And is not allowing me to input 0.20 as an input
At line 3 you are inputting into variable pg, but at line 5 you check variable cf, which doesn't appear to be set in the loop. Should you be checking pg instead?
at line 5 you check variable cf, which doesn't appear to be set in the loop. Should you be checking pg instead?
+1
Since you don't show us the declarations for cf or pg, we have to assume you've declared them correctly as floats or doubles. If you've declared them as ints, your code is not going to work.
Thanks a lot guys
so I will try using a different data type such as int or double
when I have some time I will make sure i check and close this,
@akn thanks a lot
@dhayden thats right haha thanks.
@abstraction yes i declared them as floats but why wont it work as an "int"