tic tac toe

Can someone tell me how to make this a working game?

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>

using namespace std;

int main ()
{
    int waitForNumber;
    // Named constants for array dimensions
    const int ROWS = 3;
    const int COLUMNS = 3;
    
    char board[ROWS][COLUMNS] = {{' ',' ',' '},
                                 {' ',' ',' '},
                                 {' ',' ',' '}};
    cout << "Here's the tic-tac-board: \n";
    cout << "   1  2  3\n";
    for (int i =1; i < ROWS; ++i)
    {        
        cout << i << " ";
        for (int j = 1; j < COLUMNS; ++j)
            cout << board[i][j];
        cout << endl;
    }
    
    // X makes the last move in the game
    
    cout << "You get to make the first move.\nWhere do you want it to be? \n" << endl;
    cout << "Row number is 0, 1,or 2.\nColumn number is 0, 1,or 2." << endl;
        
     
    cout << "The final tic-tac-toe board for this game is: \n";
    cout << "   1  2  3\n";
    for (int i =1; i < ROWS; ++i)
    {
        cout << i << " ";
        for (int j = 1; j < COLUMNS; ++j)
            cout << board[i][j];
        cout << endl;
    }
    
    cout << "\n'X' wins!" << endl << endl;
        
    std::cin >> waitForNumber;
    return 0;
}
Yes. You would put in code (presumably in the form of a loop) between lines 23 and 25 that would get the user's move, see if it's a valid move, check to see if the user won, make a computer's move, see if the computer won, and repeat until someone won.

An aside; if you have included the std namespace, why are you referring to cin as std::cin?

Also, your for loops should have i and j equal to 0 to begin with, not 0. If they start at one, each will get the value 1, then 2, and then the loop will stop.
Topic archived. No new replies allowed.