Thread: Boolean in a character array

1. Boolean in a character array

Hi
I am trying to get the code below displayed as X values where true, and O where false... so for the character array below, im trying to get it to output
X X X
X X O

I have tried a few things such as a for loop (which i think is used?) but it ends up outputting something stupid

Code:
```char Board[3][3] =	{ {true,true,true},
{true,true,false},};```

2. I have tried a few things...
Let's see em and we'll go from there.

gg

3. Think about the data type of 'true' and 'false'.

4. Code:
```for (int q = 0; q < 2; q++)
{

for (int p = 0; p < 3; p++)
{
if (Board[q][p] = true)
{
Board[q][p] = 'X';
cout << Board[q][p];
}

if (Board[q][p] = false)
{
Board[q][p] = 'O';
cout << Board[q][p];
}
}
cout << endl;
}```
Thats the closest ive got but i dont think its close to being correct as it just displays:
XXX
XXX
when im trying to get
XXX
XXO (As the bottom right is false)

6. First problem:

if (Board[q][p] = true)

should be:

if (Board[q][p] == true)

>> for (int q = 0; q < 2; q++)

should be:

>> for (int q = 0; q < 3; q++)

Finally, you could save yourself all of those steps by simply doing:

Code:
```#define SET 'X'
#define UNSET 'O'

char Board[3][3] =
{
{SET, SET, SET},
{SET, SET, SET},
{SET, SET, UNSET}
};```

7. For good programming practice, that really ought to be:
const char SET = 'X';
const char UNSET = 'O';

8. thanks alot
sorted