HELP PLEASE!!!:)

Im seriously new to C++ and any programming language. I do software design as a subject at school. I have an assignment where I have to write a tic tac toe game in C++. I didnt want to copy anyone elses game and I tried to start from scratch with the teachers help. However I've derived a code, I know my syntax is abit out of wack and it may not be the most logical code, but that is why I need help. Also getting the variables right. The compiler we have to use is codeblocks. Although from this I have recieved the errors I recieved were:

line: 17 error: expected ',' or ';' before '=' token
line: 20 error: two or more data types in decleration of 'Grid'
line: 34 error: expected initializer before 'int'
line: 39 error: expected ',' or ';' before 'bool'

I have a short deadline and im in a hurry to finish this. Your help would really be great. Thanks, Maryann.

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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//SDD 2012
//26/8/12 - 27/8/12
//Tic tac toe assignment

#include <iostream>
#include <string>

using namespace std;

//allowing players to be identified by their own name
string playerone ();
string playertwo ();

//variables for the spaces in the game board
char G = 1to9;
char Grid (G) = G;

//tic tac toe board for game play
void char Grid (G)
{
    cout << "_____________________________________________________"
    cout << "|" + Grid (1) + "|" + Grid (2) + "|" + Grid (3) + "|"
    cout << "_____________________________________________________"
    cout << "|" + Grid (4) + "|" + Grid (5) + "|" + Grid (6) + "|"
    cout << "_____________________________________________________"
    cout << "|" + Grid (7) + "|" + Grid (8) + "|" + Grid (9) + "|"
    cout << "_____________________________________________________"
}

void get_move

//if array has been filled then the game has ended.
int number_of_moves = (0);
//to determine whose turn it is
char current_turn = '0'

// if winner has been found
bool foundwinner = false

//Check if game is over
bool gameover = false

//main function
int main ()

{
    //Game title
    cout << "Tic Tac Toe"
    cout << "   begin   "

    {
        //allowing user to enter name and be identified by own name
        cout << "Player one enter name"
        cin >> playerone
        cout << "Player two enter name"
        cin >> playertwo
    }
    //so player names can be shown on screen.
    cout << player one << "         "<< player two << endl;

  void grid (G)

while gameover = false

void determine_turn
{
    playerone = 'X'
    playertwo = 'O'
    char current_turn ='X'
    switch turn (current_turn)

}

void get_move
{
    int move [1-9]
    if char current turn = 'X'
    {
        cout << playerone << "select a location for 'X'" << endl;
        cin >> move [1-9]
        {
            if move (1)
            grid[1] = 'X'

            if move (2)
            grid [2] = 'X'

            if move (3)
            grid [3] = 'X'

            if move (4)
            grid [4] = 'X'

            if move (5)
            grid [5] = 'X'

            if move (6)
            grid [6] = 'X'

            if move (7)
            grid [7] = 'X'

            if move (8)
            grid [8] = 'X'

            if move (9)
            grid (9) = 'X'
        }
        display Grid (G)
    }
    else
    {
        cout << playertwo << "select location for 'O'" << endl;
        cin >> move [1-9]
        {
            if move (1)
            grid[1] = 'O'

            if move (2)
            grid [2] = 'O'

            if move (3)
            grid [3] = 'O'

            if move (4)
            grid [4] = 'O'

            if move (5)
            grid [5] = 'O'

            if move (6)
            grid [6] = 'O'

            if move (7)
            grid [7] = 'O'

            if move (8)
            grid [8] = 'O'

            if move (9)
            grid (9) = 'O'
        }
    }

}


void check win
{
    if
    grid (1) == grid (4) && grid (7) or
    grid (2) == grid (5) && grid (8) or
    grid (3) == grid (6) && grid (9) or
    grid (1) == grid (2) && grid (3) or
    grid (4) == grid (5) && grid (6) or
    grid (7) == grid (8) && grid (9) or
    grid (1) == grid (5) && grid (9) or
    grid (3) == grid (5) && grid (7)

    foundwinner = true
    {
        if current_turn = '0'
        winner = playerone
        cout << "the winner is" << playerone << endl;
        else
        winner = playertwo
        cout << "the winner is" << playertwo << endl;

    }
    else
    foundwinner = false
}
if foundwinner = true
or number_of_moves (9)
gameover = true

else
(i=0; i<9; i++)

return 0
}



Last edited on
closed account (o3hC5Di1)
Hi there,

For the first two errors:

line: 17 error: expected ',' or ';' before '=' token
line: 20 error: two or more data types in decleration of 'Grid'


Problem is here:

1
2
3
4
5
6
7
8
9
10
//variables for the spaces in the game board
char G = 1to9;
char Grid (G) = G;   //(G) in definition of a regular variable is not allowed, delete it.

//tic tac toe board for game play
//void char is not a data type - you need void here because the function doesn't return anything
//also, this function has the same name name as the Grid variable above, which is causing the second error
//rename it to something like print_grid(G), because that's basically what it does 
void char Grid (G) 
{


The next two errors:

line: 34 error: expected initializer before 'int'
line: 39 error: expected ',' or ';' before 'bool'


1
2
3
4
5
6
7
8
9
10
11
12
void get_move();  //need to add (); , always end statements with a ;   

//if array has been filled then the game has ended.
int number_of_moves = (0);
//to determine whose turn it is
char current_turn = '0' ; //again, end statements with semicolons  

// if winner has been found
bool foundwinner = false ; //again, end statements with semicolons 

//Check if game is over
bool gameover = false ; //again, end statements with semicolons  


Hope that helps.
Let us know if you have any further questions.

All the best,
NwN
Topic archived. No new replies allowed.