Tic Tac Toe Game

I know how often Tic Tac Toe games are posted here, so I apologize. But, I have my game working to full capacity, except that it does not end the game. Even after 9 turns it will stop for about 20-30 seconds and then start to re-run the program. My board prints perfectly both before and when updating with the game pieces and also does not allow the users to copy over already picked locations.

So basically what I'm asking is for some help in how to finish the game. I know that I'm very close, but I've been stuck for about 3-4 hours on this. Thanks in advance for any insight.

Also, I've been getting this recurring error, and can't find out how to fix it.

line 61: warning: expression result unused [-Wunused-value]

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <iostream>
#include <cstdlib>

void gameStructure(); //creates the board
char gameBoard[9] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',}; //creates the output values
int gamePlay(); //how the game is played
char PlayerOne = 'X'; //Player 1's playing piece
char PlayerTwo = 'O'; //Player 2's playing piece
char Draw; //Determines the draw
char checkWin(); //function that checks for a winning answer
int turns; //helps users take turns
int player1; //input value for Player 1
int player2; //input value for Player 2

int main()
{
    std::cout << "\nPlayer 1, your game piece is: " << PlayerOne << std::endl; //Prints Player 1's piece
    std::cout <<   "Player 2, your game piece is: " << PlayerTwo << std::endl; //Prints Player 2's piece
    gameStructure(); //creates the initial board
    gamePlay();
    while (1){
        gamePlay();
        if(checkWin() == PlayerOne){
            std::cout << "Player 1 is the winner!" << std::endl; //Determines Player 1 victory
            break;
        }
        if(checkWin() == PlayerTwo){
            std::cout << "Player 2 is the winner!" << std::endl; //Determines Player 2 victory
            break;
        }
        if(checkWin() == Draw){
            std::cout << "The game is a draw!" << std::endl; //Determines Draw
            break;
        }
    }


    return 0;
}

//Prints the entire board
void gameStructure(){
    std::cout <<  "\n    Stavros Gogos'" << std::endl;
    std::cout << "  Tic-Tac-Toe v1.0" << std::endl;
    std::cout <<  "\n     1    2    3" << std::endl;
    std::cout <<  "\n1    " << gameBoard[0] << " |" << "  " << gameBoard[1] << " |" << " " << gameBoard[2] << std::endl;
    std::cout <<  "   ____|____|___" << std::endl;
    std::cout <<  "4    " << gameBoard[3] << " |" << "  " << gameBoard[4] << " |" << " " << gameBoard[5] << std::endl;
    std::cout <<  "   ____|____|___" << std::endl;
    std::cout <<  "7    " << gameBoard[6] << " |" << "  " << gameBoard[7] << " |" << " " << gameBoard[8] << std::endl;
    std::cout <<  "       |    |   " << std::endl;
    std::cout <<  std::endl;
}

//Plays the game
int gamePlay(){
    int turns = 0;
    int checkWin = 0;
    int player1;
    int player2;
    while(turns < 10, turns++, checkWin == 0){
        if(turns == 1 || turns == 3 || turns == 5 || turns == 7 || turns == 9){
                std::cout << "Player 1, please enter your choice of box (1-9)." << std::endl;
                std::cin >> player1; //input location for PlayerOne
                if(gameBoard[0] == ' ' && player1 == 1){ gameBoard[0] = PlayerOne;}
                else if(gameBoard[1] == ' ' && player1 == 2){gameBoard[1] = PlayerOne;}
                else if(gameBoard[2] == ' ' && player1 == 3){gameBoard[2] = PlayerOne;}
                else if(gameBoard[3] == ' ' && player1 == 4){gameBoard[3] = PlayerOne;}
                else if(gameBoard[4] == ' ' && player1 == 5){gameBoard[4] = PlayerOne;}
                else if(gameBoard[5] == ' ' && player1 == 6){gameBoard[5] = PlayerOne;}
                else if(gameBoard[6] == ' ' && player1 == 7){gameBoard[6] = PlayerOne;}
                else if(gameBoard[7] == ' ' && player1 == 8){gameBoard[7] = PlayerOne;}
                else if(gameBoard[8] == ' ' && player1 == 9){gameBoard[8] = PlayerOne;}
                gameStructure(); //updates the board with inputed value
                }

        if(turns == 2 || turns == 4 || turns == 6 || turns == 8){
                std::cout << "Player 2, please enter your choice of box (1-9)." << std::endl;
                std::cin >> player2; //input location for PlayerTwo
                if(gameBoard[0] == ' ' && player2 == 1){ gameBoard[0] = PlayerTwo;}
                else if(gameBoard[1] == ' ' && player2 == 2){gameBoard[1] = PlayerTwo;}
                else if(gameBoard[2] == ' ' && player2 == 3){gameBoard[2] = PlayerTwo;}
                else if(gameBoard[3] == ' ' && player2 == 4){gameBoard[3] = PlayerTwo;}
                else if(gameBoard[4] == ' ' && player2 == 5){gameBoard[4] = PlayerTwo;}
                else if(gameBoard[5] == ' ' && player2 == 6){gameBoard[5] = PlayerTwo;}
                else if(gameBoard[6] == ' ' && player2 == 7){gameBoard[6] = PlayerTwo;}
                else if(gameBoard[7] == ' ' && player2 == 8){gameBoard[7] = PlayerTwo;}
                else if(gameBoard[8] == ' ' && player2 == 9){gameBoard[8] = PlayerTwo;}
                gameStructure(); //updates the board with inputed value
                }
    }
    return 0;
    }


char checkWin(){

    if(gameBoard[0] == PlayerOne && gameBoard[1] == PlayerOne && gameBoard[2] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[0] == PlayerOne && gameBoard[4] == PlayerOne && gameBoard[8] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[0] == PlayerOne && gameBoard[3] == PlayerOne && gameBoard[6] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[1] == PlayerOne && gameBoard[4] == PlayerOne && gameBoard[7] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[2] == PlayerOne && gameBoard[5] == PlayerOne && gameBoard[8] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[3] == PlayerOne && gameBoard[4] == PlayerOne && gameBoard[5] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[6] == PlayerOne && gameBoard[7] == PlayerOne && gameBoard[8] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[6] == PlayerOne && gameBoard[4] == PlayerOne && gameBoard[2] == PlayerOne)
        {return PlayerOne;}

    if(gameBoard[0] == PlayerTwo && gameBoard[1] == PlayerTwo && gameBoard[2] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[0] == PlayerTwo && gameBoard[4] == PlayerTwo && gameBoard[8] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[0] == PlayerTwo && gameBoard[3] == PlayerTwo && gameBoard[6] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[1] == PlayerTwo && gameBoard[4] == PlayerTwo && gameBoard[7] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[2] == PlayerTwo && gameBoard[5] == PlayerTwo && gameBoard[8] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[3] == PlayerTwo && gameBoard[4] == PlayerTwo && gameBoard[5] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[6] == PlayerTwo && gameBoard[7] == PlayerTwo && gameBoard[8] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[6] == PlayerTwo && gameBoard[4] == PlayerTwo && gameBoard[2] == PlayerTwo)
        {return PlayerTwo;}

    if(turns == 10)
        {return Draw;}
    return 0;
}
Last edited on
1. Get rid of the gamePlay() outside the loop(you call it twice)
2. the while loop inside the play game should be a for loop like this:
1
2
3
	for (; turns < 10 && check == 0; turns++) { 
// changed from checkWin as thats a function name //


In addition, you probably want to checkWin inside your loop instead of after so the game ends ONCE somone wins and not after x number of turns.

As for an explanation as to why it's doing that weird behavior. I believe it's because using a while loop like does...something weird and thus it's continuing to run(without output because it doesn't match your "or"s until just overflows and wraps back around to < 10.
Last edited on
Thanks for your help Semoirethe,

I'm even closer now, but I'm getting stuck again. Now whenever I press enter it says the game is a draw until a player gets three in a row. Also, the game will not end until it reaches 9 turns. I feel like I might just be needing to take a break from this, but a different set of eyes always helps. Here's the updated code.

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <iostream>
#include <cstdlib>

void gameStructure(); //creates the board
char gameBoard[9] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',}; //creates the output values
int gamePlay(); //how the game is played
char PlayerOne = 'X'; //Player 1's playing piece
char PlayerTwo = 'O'; //Player 2's playing piece
char Draw; //Determines the draw
char checkWin(); //function that checks for a winning answer
int turns; //helps users take turns
int player1; //input value for Player 1
int player2; //input value for Player 2
char check();

int main()
{
    std::cout << "\nPlayer 1, your game piece is: " << PlayerOne << std::endl; //Prints Player 1's piece
    std::cout <<   "Player 2, your game piece is: " << PlayerTwo << std::endl; //Prints Player 2's piece
    gameStructure(); //creates the initial board
    gamePlay();

    return 0;
}

//Prints the entire board
void gameStructure(){
    std::cout <<  "\n    Stavros Gogos'" << std::endl;
    std::cout << "  Tic-Tac-Toe v1.0" << std::endl;
    std::cout <<  "\n     1    2    3" << std::endl;
    std::cout <<  "\n1    " << gameBoard[0] << " |" << "  " << gameBoard[1] << " |" << "  " << gameBoard[2] << std::endl;
    std::cout <<  "   ____|____|____" << std::endl;
    std::cout <<  "4    " << gameBoard[3] << " |" << "  " << gameBoard[4] << " |" << "  " << gameBoard[5] << std::endl;
    std::cout <<  "   ____|____|____" << std::endl;
    std::cout <<  "7    " << gameBoard[6] << " |" << "  " << gameBoard[7] << " |" << "  " << gameBoard[8] << std::endl;
    std::cout <<  "       |    |   " << std::endl;
    std::cout <<  std::endl;
}

//Plays the game
int gamePlay(){
    int turns = 0;
    int checkWin = 0;
    int player1;
    int player2;
       for(;turns < 10 && checkWin == 0; turns++){
        if(turns == 1 || turns == 3 || turns == 5 || turns == 7 || turns == 9){
                std::cout << "Player 1, please enter your choice of box (1-9)." << std::endl;
                std::cin >> player1; //input location for PlayerOne
                if(gameBoard[0] == ' ' && player1 == 1){ gameBoard[0] = PlayerOne;}
                else if(gameBoard[1] == ' ' && player1 == 2){gameBoard[1] = PlayerOne;}
                else if(gameBoard[2] == ' ' && player1 == 3){gameBoard[2] = PlayerOne;}
                else if(gameBoard[3] == ' ' && player1 == 4){gameBoard[3] = PlayerOne;}
                else if(gameBoard[4] == ' ' && player1 == 5){gameBoard[4] = PlayerOne;}
                else if(gameBoard[5] == ' ' && player1 == 6){gameBoard[5] = PlayerOne;}
                else if(gameBoard[6] == ' ' && player1 == 7){gameBoard[6] = PlayerOne;}
                else if(gameBoard[7] == ' ' && player1 == 8){gameBoard[7] = PlayerOne;}
                else if(gameBoard[8] == ' ' && player1 == 9){gameBoard[8] = PlayerOne;}
                check();
                gameStructure(); //updates the board with inputed value
                }

        if(turns == 2 || turns == 4 || turns == 6 || turns == 8){
                std::cout << "Player 2, please enter your choice of box (1-9)." << std::endl;
                std::cin >> player2; //input location for PlayerTwo
                if(gameBoard[0] == ' ' && player2 == 1){ gameBoard[0] = PlayerTwo;}
                else if(gameBoard[1] == ' ' && player2 == 2){gameBoard[1] = PlayerTwo;}
                else if(gameBoard[2] == ' ' && player2 == 3){gameBoard[2] = PlayerTwo;}
                else if(gameBoard[3] == ' ' && player2 == 4){gameBoard[3] = PlayerTwo;}
                else if(gameBoard[4] == ' ' && player2 == 5){gameBoard[4] = PlayerTwo;}
                else if(gameBoard[5] == ' ' && player2 == 6){gameBoard[5] = PlayerTwo;}
                else if(gameBoard[6] == ' ' && player2 == 7){gameBoard[6] = PlayerTwo;}
                else if(gameBoard[7] == ' ' && player2 == 8){gameBoard[7] = PlayerTwo;}
                else if(gameBoard[8] == ' ' && player2 == 9){gameBoard[8] = PlayerTwo;}
                check();
                gameStructure(); //updates the board with inputed value
                }
    }
    return 0;
    }


char checkWin(){

    {if(gameBoard[0] == PlayerOne && gameBoard[1] == PlayerOne && gameBoard[2] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[0] == PlayerOne && gameBoard[4] == PlayerOne && gameBoard[8] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[0] == PlayerOne && gameBoard[3] == PlayerOne && gameBoard[6] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[1] == PlayerOne && gameBoard[4] == PlayerOne && gameBoard[7] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[2] == PlayerOne && gameBoard[5] == PlayerOne && gameBoard[8] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[3] == PlayerOne && gameBoard[4] == PlayerOne && gameBoard[5] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[6] == PlayerOne && gameBoard[7] == PlayerOne && gameBoard[8] == PlayerOne)
        {return PlayerOne;}
    if(gameBoard[6] == PlayerOne && gameBoard[4] == PlayerOne && gameBoard[2] == PlayerOne)
        {return PlayerOne;}

    if(gameBoard[0] == PlayerTwo && gameBoard[1] == PlayerTwo && gameBoard[2] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[0] == PlayerTwo && gameBoard[4] == PlayerTwo && gameBoard[8] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[0] == PlayerTwo && gameBoard[3] == PlayerTwo && gameBoard[6] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[1] == PlayerTwo && gameBoard[4] == PlayerTwo && gameBoard[7] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[2] == PlayerTwo && gameBoard[5] == PlayerTwo && gameBoard[8] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[3] == PlayerTwo && gameBoard[4] == PlayerTwo && gameBoard[5] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[6] == PlayerTwo && gameBoard[7] == PlayerTwo && gameBoard[8] == PlayerTwo)
        {return PlayerTwo;}
    if(gameBoard[6] == PlayerTwo && gameBoard[4] == PlayerTwo && gameBoard[2] == PlayerTwo)
        {return PlayerTwo;}

    if(gameBoard[0] != ' ' && gameBoard[1] != ' ' && gameBoard[2] != ' ' && gameBoard[3] != ' '
       && gameBoard[4] != ' ' && gameBoard[5] != ' ' && gameBoard[6] != ' '
       && gameBoard[7] != ' ' && gameBoard[8] != ' ')
        {return Draw;}

    }
    return 0;
}

char check(){
        if(checkWin() == PlayerOne){
            std::cout << "Player 1 is the winner!" << std::endl; //Determines Player 1 victory
        }
        if(checkWin() == PlayerTwo){
            std::cout << "Player 2 is the winner!" << std::endl; //Determines Player 2 victory
        }
        if(checkWin() == Draw){
            std::cout << "The game is a draw!" << std::endl; //Determines Draw
        }
        return 0;
}

Last edited on
Line 9 defines global variable Draw. Since it's global, it's value is zero.
Line 125 returns 0 when there is no winner.
Line 135 checks if the result of checkWin() is Draw. Since Draw==0, this is true when there is no winner.

I suggest you change checkWin() to return:
X if player 1 wins
O if player 2 wins
' ' if there is no winner yet
'D' if it's a draw.

Other advice: any time you find yourself writing basically the same code over and over, there's a good chance that you can factor the code out:
Lines 51-58: math is your friend:
1
2
3
            if (gameBoard[player1-1] == ' ') {
                gameBoard[player1-1] = PlayerOne;
            }

Better yet, subtract 1 from player1 right after you read it, thus converting it from user-friendly 1-9 into code-friendly 0-8. Doing this and applying to the player2 section also gives:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
        if(turns == 1 || turns == 3 || turns == 5 || turns == 7 || turns == 9){
            std::cout << "Player 1, please enter your choice of box (1-9)." << std::endl;
            std::cin >> player1; //input location for PlayerOne
            --player1;           // Now it's 0-8
            if (gameBoard[player1] == ' ') {
                gameBoard[player1] = PlayerOne;
            }
            check();
            gameStructure(); //updates the board with inputed value
        }

        if(turns == 2 || turns == 4 || turns == 6 || turns == 8){
            std::cout << "Player 2, please enter your choice of box (1-9)." << std::endl;
            std::cin >> player2; //input location for PlayerTwo
            --player2;           // Now it's 0-8
            if (gameBoard[player2] == ' ') {
                gameBoard[player2] = PlayerTwo;
            }
            check();
            gameStructure(); //updates the board with inputed value
        }

Now these two pieces of code look nearly identical. See if you can combine them.

dhayden,

Thanks a lot for that advice, it simplified things substantially. The only problem that exists currently is that the game will not end before 9 turns. I thought that this would be fixed by the for statement that is present in playGame(); but it doesn't end. Do you have any hints that could lead me to solving this? Thank you.

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <iostream>
#include <cstdlib>

void gameStructure(); //creates the board
char gameBoard[9] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',}; //creates the output values
int gamePlay(); //how the game is played
char PlayerOne = 'X'; //Player 1's playing piece
char PlayerTwo = 'O'; //Player 2's playing piece
char checkWin(); //function that checks for a winning answer
int turns; //helps users take turns
int player1; //input value for Player 1
int player2; //input value for Player 2
char check();

int main()
{
    std::cout << "\nPlayer 1, your game piece is: " << PlayerOne << std::endl; //Prints Player 1's piece
    std::cout <<   "Player 2, your game piece is: " << PlayerTwo << std::endl; //Prints Player 2's piece
    gameStructure(); //creates the initial board
    gamePlay();

    return 0;
}
//Prints the entire board
void gameStructure(){
    std::cout <<  "\n    Stavros Gogos'" << std::endl;
    std::cout << "  Tic-Tac-Toe v1.0" << std::endl;
    std::cout <<  "\n     1    2    3" << std::endl;
    std::cout <<  "\n1    " << gameBoard[0] << " |" << "  " << gameBoard[1] << " |" << "  " << gameBoard[2] << std::endl;
    std::cout <<  "   ____|____|____" << std::endl;
    std::cout <<  "4    " << gameBoard[3] << " |" << "  " << gameBoard[4] << " |" << "  " << gameBoard[5] << std::endl;
    std::cout <<  "   ____|____|____" << std::endl;
    std::cout <<  "7    " << gameBoard[6] << " |" << "  " << gameBoard[7] << " |" << "  " << gameBoard[8] << std::endl;
    std::cout <<  "       |    |   " << std::endl;
    std::cout <<  std::endl;
}
//Plays the game
int gamePlay(){
    int turns = 0;
    char checkWin = ' ';
    int player1;
    int player2;
       for(;turns < 10 && checkWin == ' '; turns++){
        if(turns == 1 || turns == 3 || turns == 5 || turns == 7 || turns == 9){
                std::cout << "Player 1, please enter your choice of box (1-9)." << std::endl;
                std::cin >> player1; //input location for PlayerOne
                player1 = player1 - 1;
                if(gameBoard[player1] == ' ' ){ gameBoard[player1] = PlayerOne;}
                check();
                gameStructure();
                }

        if(turns == 2 || turns == 4 || turns == 6 || turns == 8){
                std::cout << "Player 2, please enter your choice of box (1-9)." << std::endl;
                std::cin >> player2; //input location for PlayerTwo
                player2 = player2 - 1;
                if(gameBoard[player2] == ' ' ){ gameBoard[player2] = PlayerTwo;}
                check();
                gameStructure();
                }
    }
    return 0;
    }

char checkWin(){

    {if(gameBoard[0] == PlayerOne && gameBoard[1] == PlayerOne && gameBoard[2] == PlayerOne)
        {return 'X';}
    if(gameBoard[0] == PlayerOne && gameBoard[4] == PlayerOne && gameBoard[8] == PlayerOne)
        {return 'X';}
    if(gameBoard[0] == PlayerOne && gameBoard[3] == PlayerOne && gameBoard[6] == PlayerOne)
        {return 'X';}
    if(gameBoard[1] == PlayerOne && gameBoard[4] == PlayerOne && gameBoard[7] == PlayerOne)
        {return 'X';}
    if(gameBoard[2] == PlayerOne && gameBoard[5] == PlayerOne && gameBoard[8] == PlayerOne)
        {return 'X';}
    if(gameBoard[3] == PlayerOne && gameBoard[4] == PlayerOne && gameBoard[5] == PlayerOne)
        {return 'X';}
    if(gameBoard[6] == PlayerOne && gameBoard[7] == PlayerOne && gameBoard[8] == PlayerOne)
        {return 'X';}
    if(gameBoard[6] == PlayerOne && gameBoard[4] == PlayerOne && gameBoard[2] == PlayerOne)
        {return 'X';}

    if(gameBoard[0] == PlayerTwo && gameBoard[1] == PlayerTwo && gameBoard[2] == PlayerTwo)
        {return 'O';}
    if(gameBoard[0] == PlayerTwo && gameBoard[4] == PlayerTwo && gameBoard[8] == PlayerTwo)
        {return 'O';}
    if(gameBoard[0] == PlayerTwo && gameBoard[3] == PlayerTwo && gameBoard[6] == PlayerTwo)
        {return 'O';}
    if(gameBoard[1] == PlayerTwo && gameBoard[4] == PlayerTwo && gameBoard[7] == PlayerTwo)
        {return 'O';}
    if(gameBoard[2] == PlayerTwo && gameBoard[5] == PlayerTwo && gameBoard[8] == PlayerTwo)
        {return 'O';}
    if(gameBoard[3] == PlayerTwo && gameBoard[4] == PlayerTwo && gameBoard[5] == PlayerTwo)
        {return 'O';}
    if(gameBoard[6] == PlayerTwo && gameBoard[7] == PlayerTwo && gameBoard[8] == PlayerTwo)
        {return 'O';}
    if(gameBoard[6] == PlayerTwo && gameBoard[4] == PlayerTwo && gameBoard[2] == PlayerTwo)
        {return 'O';}

    if(turns == 10)
        {return 'D';}

    else{return ' ';}
    }
}

char check(){

        if(checkWin() == 'X'){
            std::cout << "Player 1 is the winner!" << std::endl; //Determines Player 1 victory
        }
        if(checkWin() == 'O'){
            std::cout << "Player 2 is the winner!" << std::endl; //Determines Player 2 victory
        }
        if(checkWin() == 'D'){
            std::cout << "The game is a draw!" << std::endl; //Determines Draw
        }
        
        return 0;
}
I figured it out!

In the for loop, checkWin == ' ' should be checkWin() = ' '. Therefore getting rid of char checkWin == ' '.

Thanks for all your help!
Topic archived. No new replies allowed.