Quote:
|
Originally Posted by bdjuf
So I have this 2 dimensional Array (3X3)
and I want to make it so
"if there is an "X" in slot 2-2, return a "YES"
tried doing
if ( board[2][2] hahahaha 'X' )
{
cout << "Yes";
}
else
{
cout << "No";
}
and I keep on getting "No"s at every turn
can anybody help me out on this one?
what I am actually trying to do, is that it's a TIC TAC TOE game, and I need to stop the program once someone wins...
help me out yooo!!!
178340550
|
Because [2][2] is actually referencing the 'bottom right' element of a 3x3 array. Arrays in C/C++ are referenced from 0. If you're trying to check the MIDDLE square, you're checking the wrong spot... and if you reference [3][3], you're overflowing and begging for a h4x0r 2 r0x0r j00r b0x0rz.
Try this:
Code:
if(board[1][1]hahahaha'X') { // Is there an X in the middle square?
cout << "Yes";
} else {
cout << "No";
}
BTW - The best way to make a TTT game is to have the program 'learn'. I did the same thing back in 80s on an atari 400... it's possible to make a damn-near unbeatable computerized opponent.