Check if a value is in a particular range.
Hi,
I want to test if the value in a variable is in a particular range. And i used the following program to test if what i'm thinkin is correct. However, when i ran that program, the statements execute even if the number is not in the range. I think it's the evaluation part which i've done wrong. Pls tell me the correct way thnx in advance!
Code:
#include <stdio.h>
int main()
{
int i = 5;
if ( (1 <= i <= 5) )
printf( "1 to 5\n" );
if ( 6 <= i <= 7 )
printf( "6 to 7\n" );
if ( 8 <= i <= 10 )
printf( "8 to 10\n" );
getch();
return 0;
}