[code\]
int a=5;
if (a==7||6||5||4||3||2)
instead of doing
int a=5;
if (a==7||a==6||a==5||a==4||a==3||a==2)
[code/]
is this possible and if not how can you make it possible?
Printable View
[code\]
int a=5;
if (a==7||6||5||4||3||2)
instead of doing
int a=5;
if (a==7||a==6||a==5||a==4||a==3||a==2)
[code/]
is this possible and if not how can you make it possible?
is not going to do what you want it to (the condition will always be true). Instead doCode:int a=5;
if (a==7||6||5||4||3||2)
or use a switch statementCode:if( a >= 2 && a <=7 )
// Do something
Code:switch( i )
{
case 7:
case 6:
case 5:
case 4:
case 3:
case 2:
//Do something
break;
default:
break;
};
You may overload operator "||". But it is not recommanded.
No it's not possible. C++ does not understand colloquial English. Just because English speakers shorten their "or's" by combining everything into one sentence doesn't mean it works for C++.
Every comparison must be explicitly stated, one at a time.
Didn't you do that already?Quote:
and if not how can you make it possible?
Regards,Code:int a=5;
if (a==7||a==6||a==5||a==4||a==3||a==2)
Paul McKenzie