Error in program

This is the program I am working on but when i debug it, I get an error which says,"error C1075: end of file found before the left brace '{' at 'Tic Tac Toe.cpp(137)' was matched".


// Tic Tac Toe.cpp : main project file.

#include "stdafx.h"
#include <iostream>
#include <string>


using namespace std;
using namespace System;

//declare gobal varibles
char Board[9];

//Decalre function
void showboard();
bool moveIsValid(int m);
int whoWon(); //Return 0 if tie game, 1 if player 1 wins, and 2 if player 2 wins

void main()
{
//delcare local variables
string Player_1_Name;
string Player_2_Name;
int Whose_Turn = 1; // 1 means its player 1's turn, 2 means its player 2's turn
int Move; // stores where the player wants to move
int Total_Moves = 0;

//assign values to the playing Board
Board[0] = '0';
Board[1] = '1';
Board[2] = '2';
Board[3] = '3';
Board[4] = '4';
Board[5] = '5';
Board[6] = '6';
Board[7] = '7';
Board[8] = '8';

//get player names
cout << "Player 1: Please enter your name." << endl;
cin >> Player_1_Name;
cout << "Player 2: Please enter your name. " << endl;
cin >> Player_2_Name;

while (whoWon() == 0 && Total_Moves < 9)
{
// do this until the layer chooses a vaild move
do
{
//Show the board
showboard();

// tell which player to move
if (Whose_Turn == 1)
{

cout << Player_1_Name << ": It's your turn." << endl;
}
else
{
cout << Player_2_Name << ": It's your turn." << endl;
}

// get the move
cout << "Enter the number of teh spot where you would like to move" << endl;
cin >> Move;
} while (moveIsValid(Move) != true);
// Add 1 to total moves
Total_Moves++;
//change_whose turn is it
switch (Whose_Turn)
{
case (1) :
{

Board[Move] = 'x';
Whose_Turn = 2;
break;
}
case(2) :
{
Board[Move] = 'o';
Whose_Turn = 1;
}
}
}

//Show the board
showboard();
if (whoWon() == 1)

{
cout << Player_1_Name << "; has won the game!" << endl;
}
else if (whoWon() == 2)
{
cout << Player_2_Name << "; has won the game!" << endl;
}
else
{
cout << "It's a tie game!" << endl;
}

system("PAUSE");
}

void showboard()
{
cout << endl;
cout << Board[0] << " | " << Board[1] << " | " << Board[2] << endl;
cout << "---+---+--" << endl;
cout << Board[3] << " | " << Board[4] << " | " << Board[5] << endl;
cout << "---+---+--" << endl;
cout << Board[6] << " | " << Board[7] << " | " << Board[8] << endl;
cout << "---+---+--" << endl;
cout << endl;

}


bool moveIsVaild(int m)
{
if (Board[m] != 'x' && Board[m] != 'o')
{
return true;
}
else
{
return false;
}

}

int whoWho()


{ if (Board[0] == Board[1] && Board[1] == Board[2])
{
if (Board[0] == 'x')
{
return 1;
}
else
{
return 2;
}
}
if (Board[3] == Board[4] && Board[4] == Board[5])
{
if (Board[3] == 'x')
{
return 1;

}
else
{
return 2;
}
}
if (Board[6] == Board[7] && Board[7] == Board[8])
{
if (Board[6] == 'x')
{

return 1;

}

else
{
return 2;
}
if (Board[0] == Board[3] && Board[3] == Board[6])
{
if (Board[0] == 'x')
{

return 1;

}

else
{
return 2;
}
}

if (Board[1] == Board[4] && Board[4] == Board[7])
{
if (Board[1] == 'x')
{

return 1;

}

else
{
return 2;
}
}

}if (Board[3] == Board[5] && Board[5] == Board[8])
{
if (Board[2] == 'x')
{

return 1;

}

else
{
return 2;
}
if (Board[0] == Board[4] && Board[4] == Board[8])
{
if (Board[0] == 'x')
{

return 1;

}

else
{
return 2;
}
}
if (Board[2] == Board[4] && Board[4] == Board[6])
{
if (Board[2] == 'x')
{
return 1;
}
else
{
return 2;
}
}
}
Looks like you have a missing } somewhere. If you format your code properly it should be easy to spot. In case your editor/IDE doesn't support formatting you can try an online formatter:
http://www.tutorialspoint.com/online_c_formatter.htm
Hi i work on your code and apply some improvements on it.
this work is in progress i update it soon.

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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/// Start of tic tac toe.c

/*
 * tic tac toe.c
 * 
 * CopyLeft 2017 eec
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 * 
 */


/*
 * 
 * include : files
 * 
 */

#include <stdio.h>


/*
 * 
 * declare variable : Global
 * 
 */
 
char board[9];



int mov;


/*
 * 
 * declare functions : prototype
 * 
 */
 

/*
 * 
 * name: showboard
 * @param  : void
 * @return : void
 * 
 */
void showboard(void);

/*
 * 
 * name: main
 * @param  : int argc, char  **argv
 * @return : int: 0
 * 
 */
bool moveIsValid(int);


/*
 * 
 * name: whoWon
 * @param  : void
 * @return : char : d, whic player wins the game
 * 
 */
char  whoWon(void); //Return 0 if tie game, 1 if player 1 wins, and 2 if player 2 wins


/*
 * 
 * name: turn
 * @param  : int t, char &c
 * @return : void
 * 
 */
void turn(int t,char &c){
	
	if (t==1){
		c = 'x';	
	}
	else {
		c = 'o';
	}
		
}



/*
 * 
 * name: main
 * @param  : int argc, char  **argv
 * @return : int: 0
 * 
 */

void
getinput(){
	scanf("%d",&mov);			
}

/*
 * 
 * name: main
 * @param  : int argc, char  **argv
 * @return : int: 0
 * 
 */
int 
add_to_table(int mov, char c)///char c is turn 
{
	
	switch (mov){
		
	case 7: board[0] = c; break;
	case 8: board[1] = c; break;
	case 9: board[2] = c; break;
	
	case 4: board[3] = c; break;
	case 5: board[4] = c; break;
	case 6: board[5] = c; break;
	
	case 1: board[6] = c; break;
	case 2: board[7] = c; break;
	case 3: board[8] = c; break;
	default: printf("error\n");return 0;break;
	}
	return 1;
}



/*
 * 
 * name: main
 * @param  : int argc, char  **argv
 * @return : int: 0
 * 
 */
int 
main(int argc, char  **argv)
{
	
	///delcare local variables
	char c = 'z';///player sign in each turn
	char d;///temp to hold won player
	int t=0;/// counter to draw

	///assign values to the board
	board[0] = '7';
	board[1] = '8';
	board[2] = '9';
	
	board[3] = '4';
	board[4] = '5';
	board[5] = '6';
	
	board[6] = '1';
	board[7] = '2';
	board[8] = '3';

	/// calculator keys	
	/*
		|7 | 8 | 9 |
		|4 | 5 | 6 |
		|1 | 2 | 3 |
	*/	
	/// why i cant assign value in above main


showboard();
	while(1){
		turn(1,c);
		printf("turn : %c\n",c);
		getinput();
		add_to_table(mov,c);	
		showboard();
		t++;
		printf("t 1:::%d\n\n",t);
		d=whoWon();
		
		///if (d != 'q'){break;}
		if (t==9 || d != 'q'){break;}
		
		turn(2,c);
		printf("turn : %c\n",c);
		getinput();
		add_to_table(mov,c);
		t++;
		showboard();
		d=whoWon();
		printf("\nt 2:::%d\n\n",t);
		if (d != 'q'){break;}/// this piont palyer o can win but draw npt acuur
		
	}

	if (d!='q'){
		printf("player %c won the game\n",d);
		
	}
	else {
		printf("draw\n");
	}
	
	getchar();
	
	return 0;
}
///end main



/// return type char shows player won 
char
whoWon()
{
	/// 1 2 3
	if ((board[6] == board[7]) && (board[7] == board[8])){
		return board[6];
	}

	///1 5 9 
	if ((board[6] == board[4]) && (board[4] == board[2])){
		return board[6];
	}

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

	///4 5 6
	if ((board[3] == board[4]) && (board[4] == board[5])){
		return board[3];
	}
	
	///3 5 7
	if ((board[8] == board[4]) && (board[4] == board[0])){
		return board[4];
	}
		
	///7 8 9
	if ((board[0] == board[1]) && (board[1] == board[2])){
		return board[0];
	}
	
	return 'q';
}
///end whoWon


void 
showboard()
{
	printf("__________\n\n");
	printf("%c | %c | %c\n",board[0],board[1],board[2]);
	printf("--|---|--\n");
	printf("%c | %c | %c\n",board[3],board[4],board[5]);	
	printf("--|---|--\n");
	printf("%c | %c | %c\n",board[6],board[7],board[8]);
	printf("__________\n");
	
}


bool 
moveIsVaild(int m)
{
	if (board[m] != 'x' && board[m] != 'o')
	{
		return true;
	}
	else
	{
		return false;
	}

}



Topic archived. No new replies allowed.