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!

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 5 Years Ago by Moschops: n/a

&& 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.