tic tac toe program
fixed
Last edited on
no one can help me?
Line 5-6: Globals should be avoided.
Line 13: You're declaring a local named chesboard which goes out of scope when the function exists. You should be using the passed parameter (cb).
Line 22: This is going to cause a trap. You;re referencing an out of bounds location. i.e.
1 2
|
cout << chessboard[3][3]; // Equivalent statement. Out of bounds reference
|
Line 32: You have a redundant term. cb[i][j] appears twice. No harm, but unnecessary.
Line 41: Why are you passing cb, if you insist on using the global chessboard?
Lines 67-85: I don't understand the point of these lines. You've already checked for a winner.
I tried to fix according to your ideas but somehow it still wont work correctly
Without seeing your updated code, I can't tell you what's wrong.
Line 32: Your condition is wrong.
|
if (i == 0 && i < DIM - 1 && cb[i][j] == 'B' && j == 0 && j < DIM - 1 && cb[i][j] == 'B')
|
That statement can only ever be true when i and j are 0.
You want:
|
if (i >= 0 && i < DIM - 1 && cb[i][j] == 'B' && j >= 0 && j < DIM - 1)
|
Last edited on
Topic archived. No new replies allowed.