To clarify what others have already mentioned and to explain what the compiler* does:
When you write:
float stepsRemaining_float = 30 / 100;
The compiler first evaluates the expression on the right-hand side. It sees 30 / 100 and determines the types of the constants. Since both 30 and 100 are integral values and fit into an int, they are implicitly treated as int.
Next, the compiler performs the division operation. In C++, dividing two integers results in an integer, with any decimal part being truncated.
Since 30 / 100 equals 0.3, but both operands are integers, the result is truncated to 0, which remains an int.
Finally, the compiler processes the assignment. It notices that an int is being assigned to a float, which is allowed. An implicit conversion then takes place, converting 0 (of type int) to 0.0 (of type float).
* side note : as all this can be evaluated at compile time, the compilation process will not generate any code for this and just keep
float stepsRemaining_float = 0;
which you had in the previous line and so will just get rid of the statement altogether.
[EDIT: removed confusing link about constant folding — wikipedia entry below by @alto777 is the right idea]
spells things out in language closer to readable by mere humans.
Unless constant folding isn't constant folding? I can't make heads or tails of the cppreference.com link, not in my current condition anyway.
I also don't understand
The previous line here
float stepsRemaining_float = 0.0;
is a definition of a floating point variable with an initial value of 0. How that changes what is done, or not done, with the following assignment is not clear to me.
sorry - wrong link, too quick of a search and linked without exactly looking at what I was sharing .
Fold expressions in C++17 are a feature specifically for variadic templates, allowing you to apply an operator across all elements of a parameter pack...
Thank you all for the response. I didn't know it would treat it as an int.
I'm new to this IDE, not really sure how to debug this or step through the code.
I've been uploading to my esp32 and trying it that way in serial.
Looks like there's still a lot to learn.