Problem with a switch statement.
This is a switch statement that works with a float variable. I am trying to discover why it is allowed to work. I can think of only three answers:
1. Float isn't really float.
2. It figures the value out within the parameters defined with round-off.
3. The compiler is in error.
Code:
# include <stdio.h>
int main () {
float x;
printf("Enter a number: ");
scanf("%f", &x);
if (x < 0)
{
printf("Please use a postive number.");
return 1;
}
switch(0 <= x && x <= 10)
{
case 1:
printf("OK");
break;
default: printf("hi"); break;
}
return 0;
}
Thanks for any help with this. It has been bothering me quite a bit.