+ 1
why we can't pass float variable in a switch case in C or C++?
3 Answers
+ 1
Floats are not exact. There are cases where too different real numbers will be equal when stored as floats. That makes them bad candidates for equality checks like switches.
0
Because Switch doesn't take that data type.
0
It's "simple": you could write 0.3333333333333333 and 0.3333333333333331 as two different pattern. But, at compilation time, once floating-point is not precise, both values could result in the same pattern. That means your code is meaningless.