Error: switch quantity not an integer in C
The switch statement only works with integral type of values/variables, integral types like integer, character.
The error switch quantity not an integer occurs if the value/variables passed in the switch statement is not either integer or character.
Example:
Output
prog.c: In function ‘main’: prog.c:7:9: error: switch quantity not an integer switch(choice){ ^~~~~~ prog.c:5:9: warning: variable ‘choice’ set but not used [-Wunused-but-set-variable] float choice = 2.0f; ^~~~~~How to fix?
Use only integral variables/values with the switch statement. In this example, we changed type of choice variable from float to int.
Correct code:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer