As I write this I realise that my question is most likely not specific to C++, but I encountered the "problem" while writing C++ with openFrameworks.
My question is simple: Why do these two if statements produce different results?
Statement 1 (doesn't work):
if (exploded) {
age += explodeRate;
if (age > timetodie) { exploded = false; }
}
Statement 2 (works):
if (exploded) {
if (age < timetodie) { age += explodeRate; }
else { exploded = false; }
}
I use the variable age to help calculate the size of an explosion. With statement 1 the explosions will forever expand, and with statement 2 they'll stop when I want them to stop.
In Statement 1, if exploded is true, age is always incremented by explodeRate, whereas in Statement 2, age is only incremented if it less than timetodie.
In Statement 1, if age == timetodie, exploded is not altered.
you are confusing the == operator with the operators < ,> <= ,>=
with statement 1 assuming age is 1 and time to die is 1, because 1 is not greater than 1 the condition evaluates to false , and it skips the body of control statement.
however if he said something like
1 2 3 4 5
if( age >= timetodie)
{
returnfalse;
}
then what you said would be true becasuse 1 is greater than or equal to 1
@mandarin
looking at your problem ,what are your test values for age, timetodie, and explodeRate