0
if ( initialize == "off" && Iminor > 20 || Imedium > 10 || Isevere > 5 || Ifatal > 0 )

the string type 'initialize' is cout'ing "on" and all of the values right of the AND operator are TRUE. Why is the subsequent code block for the if statement being executed? thanks!

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by lexusdominus
1

This is a big OR statement. It says...

If any of the following four things are true, execute the statement:
1) initialize == "off" && Iminor > 20
2) Imedium > 10
3) Isevere > 5
4) Ifatal > 0

You say that 2, 3 and 4 all come out as true? Well then, it seems clear that the statement will be executed.

Did you mean this:

if ( (initialize == "off") && (Iminor > 20 || Imedium > 10 || Isevere > 5 || Ifatal > 0))
which says execute the statement if initialize == "off" and any of the following things are true:
Iminor > 20
Imedium > 10
Isevere > 5
Ifatal > 0

Edited by Moschops: n/a

1

&& has higher precedence than ||, so the evaluation looks like this:

if ( (initialize == "off" && Iminor > 20) || Imedium > 10 || Isevere > 5 || Ifatal > 0 )

When what you really want is this:

if ( initialize == "off" && (Iminor > 20 || Imedium > 10 || Isevere > 5 || Ifatal > 0) )
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.