0

I have C function:

void in_range_3_7(int z) {
   if (3 < z < 7) {
      printf("Yes"); 
   } 
   else { 
      printf("No"); 
   }
}

Condition

if (3 < z < 7)

always returns 1.

How to make this condition work correctly?

L1M80 54N
  • 11
  • 3
  • 2
    Try `if (z >= 3 && z <= 7) { ...` for both inclusive. – pzaenger Jan 13 '22 at 13:13
  • 1
    You cannot program C (or any other language) by trial and error. Don't _assume_ that the syntax is as you would like it to be. – Lundin Jan 13 '22 at 13:20
  • 1
    `(3 < z < 7)` is the same as `((3 < z) < 7)` where `(3 < z)` results in either `1` (true) or `0` (false). Both values are less than `7`. – Bodo Jan 13 '22 at 13:22
  • I'll modify @pzaenger's suggestion and recommend `if (3 <= z && z <= 7) {}` – torstenvl Jan 13 '22 at 13:28

0 Answers0