help me in my game

i have two problems , first, its not putting X or O on the board.

second, notice when you play it. it takes 2 enter before the next player turn.
i mean , example

player 1's turn
input: 1
input: 2
player 2's turn
input: 3
input: 4
player 1's turn
and then again and again
it should be
player 1's turn
input : 1
player 2's turn
input : 2
player 1's turn
input 3
and so on and so ford til one of them win


heres my code http://codeviewer.org/view/code:44d6
Last edited on
Line 89 / 99 should be inside brackets of the else block otherwise the cin on those lines will always run regardless if its player one or two's turn - that will correct your double entry issue.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

void TicTacToe::players_turn(int multiplayer_loop_func) {
	if (decisions_turn() == true)
	{
		if (multiplayer_loop_func % 2 == 0) {
			cout << "Player 1's turn" << endl;
			cin >> player1_turn.slot_pick;
		}
		else {							// ADDED BRACKET
			cout << "Player 2's turn";
			cin >> player2_turn.slot_pick;
		}							// ADDED BRACKET
	}
	else
	{
		if (multiplayer_loop_func % 2 == 0) {
			cout << "Player 2's turn" << endl;
			cin >> player2_turn.slot_pick;
		}
		else {							// ADDED BRACKET
			cout << "Player 1's turn";
			cin >> player1_turn.slot_pick;
		}							// ADDED BRACKET
	}
}


I don't see any code which displays the contents of the board array, all you do is draw the grid so even if you update that board array you wouldn't know unless you debug stepped it.

There may be other issues but that's what stood out to me.


Last edited on
thanks for fixing the second problem.

I don't see any code which displays the contents of the board array, all you do is draw the grid so even if you update that board array you wouldn't know unless you debug stepped it.

that was what i thinking... on the first before i modified it
that board is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void TicTacToe::gameBoard() {
    cout << "*----*----*----*" << endl;
    for ( int H = 0; H < 3; H++ ) // H means height
    {
    for ( int W = 0; W < 3; W++) // W means width
    {
       if ( board [ H ][ W ] == '1')
       {
           cout << "|    ";
       }
    }
    cout << "|\n*----*----*----*\n" ;
    }
    }



its fix now . finally all is left is rules and the board's grid when turning
http://codeviewer.org/view/code:44f0

thank you
Last edited on
Topic archived. No new replies allowed.