# Thread: if else statement problem two

1. ## if else statement problem two

look at this code below
Code:
```printf(“range =”);scanf(“%i”,&range);
printf(“target =”);scanf(“%i”,&target);
if( ( (range==target)>0) && ( (range==target)<10) )```
when i compile this code, it isn’t the expected output i want
example, range=12 and target=12, it will go to else not if true
simple way says, the range==target must between >0 and <10
0 < range==target < 10
any ideas?

2. range == target && range >= 0 && range <= 10

3. Salem has suggested the condition you actually need to test.

To understand your problem it is also useful to understand what the condition you tested actually means.

First remember that in C, a non-zero integer value corresponds to true, and zero to false.

Code:
`if( ( (range==target)>0) && ( (range==target)<10) )`
First this evaluates the expression "range == target". If range and target are equal, that yields a value of 1, so ((range == target) > 0) is equivalent to (1 > 0), which has a value of 1 (true). Hence it is necessary to evaluate the second part of the expression (after the &&). Evaluating ((range == target) < 10) is equivalent to (1 < 10), which yields 1.

Hence the test is equivalent to
Code:
`   if (1 && 1) ...`
1 && 1 is always true.

The expression you chose is certainly not equivalent to your intended test "the values are equal, both greater to zero, and both less than 10".