0
Correct way to declare floating literal
always add f or F next to the value of variable so that compiler would understand that this is a floating literal otherwise it will take any number having point as a double by default https://code.sololearn.com/cZyAYzg7D925/?ref=app
4 Respostas
+ 3
@AMIT KUMAR
I didn't have any problem in changing all occurence of 2.6 in your code to 2.6f even in code playground...
+ 1
But then again, it's not a very good idea to use == with a floating point number in the first place :P
0
try float n=2.6f
it won't work here but definitely on other compilers like turboc++ ,dev C++ etc.
0
@Dennis I know but here I just want to explain that your number will no longer be the same while performing any other operations on that floating number, it's just a logical error which could make your program less accurate so we better use f or F next to the numbers to correct it.