Hello,

How can we compare more than two integers in an if statement?

For example;

if(a==b==c==d==e)

This gives an error since the first operation gives a boolean result and tries to compare it with the next integer.

Thanks..

Printable View

- 05-16-2011, 01:53 PMmalaguenaMultiple comparisons
Hello,

How can we compare more than two integers in an if statement?

For example;

if(a==b==c==d==e)

This gives an error since the first operation gives a boolean result and tries to compare it with the next integer.

Thanks.. - 05-16-2011, 02:08 PMPetr
Use logical operations && ||

For example

Code:`if (a==b && b==c && c==d && d==e)`

- 05-16-2011, 02:09 PMNorm
The == operator takes two operands.

Break your expression up into pairs of operands and connect with ANDs.

a==b && b==c ... - 05-16-2011, 03:23 PMmalaguena
Thank you very much for the replies!

- 05-18-2011, 11:37 AMTolls
Reporting spam.