Tic Tac Toe problem

This is a Tic Tac Toe game that I am trying to make for my spare time but there are a few errors in it that I don't know how to fix. Can anyone help me?

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
#include <cstdlib>
#include <iostream>

using namespace std;

// ===================   Structures   ==================

struct player
{      string name;
       int score;
       char symbol;
};
// ================== Prototypes =================

void intro();
void displayBoard();
void checkForWinner(player);
player makeMove(player);


// ================== Global Variables =================
player player1, player2;
bool gameOn = true;
char board[3][3] = {' ',' ',' ',' ',' ',' ',' ',' ',' '};
int scores[3][3] = {2, 3, 5, 7, 11, 13, 17, 19, 23};
// These values are all primes. The products (multiplication) of any of these 
// values will produce a unique score for every configuration of the board.
// 
// There are only a 8 possible products that represent a winning combination
// Ex:  2 X 3 X 5 = 15 represents a win along the top row. So any score that is 
//      divisible by 15 represents a board where the player has won along the top row
// The 8 possible winning values are
//       top row:       2 X 3 X 5 = 15       left column:    2 X 7 X 17 = 238
//       middle row:  7 X 11 X 13 = 1001     middle column: 3 X 11 X 19 = 627
//       bottom row: 17 X 19 X 23 = 7429    right column:   5 X 13 X 23 = 1495
//       diagonal from top left:    2 X 11 X 23 = 506
//       diagonal from top right:   5 X 11 X 17 = 935



// ===================   Definitions   ==================

void checkForWinner(player _player) // THERE ARE NO ERRORS IN THIS FUNCTION
{    if ((_player.score % 15==0) or (_player.score % 1001 ==0)or (_player.score %7429 ==0)or (_player.score %238 ==0)or (_player.score % 627 ==0)or (_player.score % 1495==0)or (_player.score % 506 ==0)or (_player.score %935 ==0))
     {  cout << _player << "   WINS!!!!!" << endl;
        gameOn = false;
     }
}

makeMove(player _player)
{    int xcoordinate=0;
     int ycoordinate=0;
     cout <<  "It is " << _player.name << "'s turn (" _player.symbol<< ")" << endl;   
     
     do
     {
     cout << "Enter the column in which you want to play " << endl;
     cout << "(left side = 1,  middle = 2, right side = 3)" ;
     cin >> ycoordinate
     cout <<"Enter the row in which you want to play " << endl;
     cout  "(top = 1,  middle = 2, bottom = 3)" ;
     cin >> xcoordinate;
     }while (board[xcoordinate-1][ycoordinate-1]!=' ');
     board[xcoordinate-1][ycoordinate-1] == _player.symbol;
     _player.score *= scores[xcoordinate-1][ycoordinate-1];
     system("CLS");
     return _player;
}
     



void displayBoard()
{    for (int i=0; i< 2; i++)
     {    cout << "-------------" << endl;
          for (int j=0; j<2; j++)
          {   cout << "| " << board[i][j] <<" "
          }
          cout << "|" << endl;
     }
     cout << "-------------"<< endl;
}

void intro()
{    cout << "Player 1, what is your name ";
     cin >> player1.name;
     cout << "Player 2, what is your name ";
     cin >> player2.name;

     player1.score=1;
     player2.score=1;
     player1.symbol=='O';
     player2.symbol = 'X';
}

int main(int argc, char *argv[])
{   intro;
    displayBoard();     
    while (gameOn)
    {     player1 = makeMove(player1);
          displayBoard();
          checkForWinner(player1);
          if (gameOn)
          {  player2 = makeMove(player2);
             displayBoard();
             checkForWinner(player2);
          }
    }
    system("PAUSE");
    return EXIT_SUCCESS;
}
makeMove(player _player)

You're missing the type of the function - player makeMove(player _player)

{ cout << _player << " WINS!!!!!" << endl;

_player is an instance of the player struct. So what exactly are you trying to print out? Surely you want the name right? cout << _player.name;

cout << "It is " << _player.name << "'s turn (" _player.symbol<< ")" << endl;

You should read your errors, they're telling you what's wrong. You're missing a <<. It should look like this -

cout << "It is " << _player.name << "'s turn (" << _player.symbol << ")" << endl;

cin >> ycoordinate

missing semicolon.

cout "(top = 1, middle = 2, bottom = 3)" ;

missing <<.

1
2
3
 for (int j=0; j<2; j++)
          {   cout << "| " << board[i][j] <<" " // missing semicolon...
          }


The errors should in most cases tell you in which line of code the error is. Then you just have to read the error. If it says missing semicolon, then look at that line of code and you'll notice you have no semicolon.

Edit: Just to clearify, not trying to be rude.
Last edited on
Interesting approach using the product of primes to determine the winner.

You might check your arithmetic though.
Last time I checked, 2 x 3 x 5 was 30, not 15.

Also, not clear how you code handles a tie.

Last edited on
I did realize some of those problems too. I'm just starting out with c++ coding and I've been mostly teaching myself since my teacher doesn't really teach, unfortunately. It's all a self taught class. Plus I know some people in this class which are really good at coding.
But thank you for your help. It's made it easier to fix now.
Last edited on
Topic archived. No new replies allowed.