The main if statement, the operator <= undefined

I am new to programming

if( (N%2==0) && (6<=N<=20) ) 

Throws an error below

The operator <=is undefined for the type of the argument. int
Please help me fix this.

+4
source share
3 answers

You cannot put together a statement like this. You need &&him.

For example,

if ((N % 2 == 0) && (6 <= N && N <= 20)) {...} 

The reason you get the error is the first condition 6 <= Nthat resolves boolean, and then you try to check if there is boolean <=for int. This is not calculated.

+5
source

You cannot compare 2 conditions in one check, you need to divide it into two checks.

if (N % 2 == 0 && N >= 6 && N <= 20) 
+2
source

(& & ):

if (N % 2 == 0 && N>=6 && N <= 20)
0

Source: https://habr.com/ru/post/1625693/


All Articles