Tic Tac Toe Problem

Hi,
I have been working on a Tic Tac Toe game and i keep coming up with random preprocessing errors and random stuff about scopes, here is the code, can someone please tell me what is wrong with it...


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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <cstdlib>  
#include <stdlib.h>

using namespace std;

int main()
{
    srand(static_cast<unsigned int>(time(0)));
    const int ROWS = 3;
    const int COLLUMS = 3;
    char board[ROWS][COLLUMS] = {{'.', '.', '.'}, //Sets up the board
                                 {'.', '.', '.'},
                                 {'.', '.', '.'}};

        cout << "From top left corner, y then x\n"; //Instructions
        for (int i = 0;i < ROWS;++i)
        {
           for (int j = 0;j < COLLUMS;++j)
           {
               cout << board[i][j];
           }
           cout << endl;
        }

        int user_input1;          
        int user_input2;

        cin >> user_input1;             //Gets user input for placement of X
        cin >> user_input2;
        board[user_input1][user_input2] = 'X';      

        for (int i = 0;i < ROWS;++i)
        {
           for (int j = 0;j < COLLUMS;++j)
           {
               cout << board[i][j];
           }
           cout << endl;
        }
        void computer_guess()   //Gets the computere to guess
        {
            int randguess1 = ((rand() % 3)+ 1);
            int randguess2 = ((rand() % 3)+ 1);
            if (board[randguess1][randguess2] == ' ' && board[randguess1][randguess2] != 'X')
            {
                board[randguess1][randguess2] = 'O';
            }
            else
            {
                computer_guess();
            }
        }
        return 0;
        
        //Not completed, i just want it to get your guess and the computers guess for now :)


}
Last edited on
read error codes and look on the internet what does they mean - then fix it yourself, otherwise you wont learn.

PS. that code is full of errors and it doesnt compile at all.
ps2. dont create functions in other functions, like void computer_guess() inside main.
Last edited on
Do you still need help with your game?
1
2
const int ROWS = 3;
const int COLLUMS = 3;


Your computer will recognize both object as interger, a value. Then this:

char board[ROWS][COLLUMS]

Read your book again.
Last edited on
Sorry, i was sloppy with my code and i was tired and confused i looked over it a day after and i fixed it all up and finished the game, i forgot to close the topic, Thanks for the help anyway
Topic archived. No new replies allowed.