[Solved] Float not working with switch


As the comments suggest: expected behavior. You can’t switch on a variable of type float.

The answer is: that would be a bad idea anyway. Keep in mind that floating point numbers are “inaccurate” by design (see here for example). Whereas switch has the notion of exactly matching n different cases. But that is simply technically not possible for floating point numbers.

In that sense: step back, and change the type of that variable to int for example. It should be int skift – not float.

And as you then ask: “but how do I get a random int number?” – see here.

2

solved Float not working with switch