Hi, how to have muilti-conditions on an IF statment?
Hi, how to have muilti-conditions on an IF statment?
Code:if (a == b && c == d) { // true }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
thanks, this board ROCKS! Im almost done my first c++ program, TIC TAC TOE!
hm,, why this dont workCode:if (playerturn % 2 == 1 && boardarray2[moverow][movecollumn]=false)
For the sake of an example, let's deal with expressions with integer values:
In C, expressions that evaluate to non-zero values are considered "True" when participating in logical operations. Expressions that evaluate to zero are considered "False".
Here's the example using the && logical operator:
Here's how it goes: first_stuff is evaluated. If it has a zero value, control passes to the else block. If first_stuff has a non-zero value, second_stuff gets evaluated. If this has a zero value, control passes to the else block. The only way that the first block in this example ever gets executed is whenever both first_stuff and second_stuff are non-zero (true).Code:if (first_stuff && second_stuff) { // This is executed if both are true } else { // This is excuted if neither is true }
Dave
= should be ==.Code:if (playerturn % 2 == 1 && boardarray2[moverow][movecollumn]=false)
>>boardarray2[moverow][movecollumn]=false)
How many equals sign are needed to test two variables? Two. One is an assignment, not a comparison.
[edit]
Doh! beat.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
But isn't it: if( true )? That means instead of == false you could also do: if( !condition ). ! meaning not, and that being true, the same thing as false. Right?
- SirCrono6
From C to shining C++!
Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
- Bubba
IDE and Compiler - Code::Blocks with MinGW
Operating System - Windows XP Professional x64 Edition
>Right?
Right (since we are talking about a boolean value). If you were talking about a general test against 0 then I would probably disagree on the grounds that using (!condition) when (condition == 0) would be more sensible results in obscure code. But if the condition being tested really is boolean in nature, (!condition) is usually more clear.
My best code is written with the delete key.