tic tac toe problem

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
#include<iostream>
#include<conio.h>
using namespace std;
char square[10] = {'o','1','2','3','4','5','6','7','8','9'};
void box();
int checkwin();
int main()
{
	char f, g,  e[10]={'o','1','2','3','4','5','6','7','8','9'};
	int a;
	int   c, d;
	for(a=1;(a<=9);a++)
	{
		int b;
		system("CLS");
		box();
if(a%2==1)
{
	cout<<"player 1 enter your num\n";
	cin>>b;
}

else 
{
	cout<<"player 2 enter you number\n";
cin>>c;	
}
if(b==1&&square[1]=='1')
square[1]='X';
else if(b==2&&square[2]=='2')
square[2]=='X';
else if(c==1&&square[1]=='1')
square[1]='O';
}
getch();
return 0;
}
void box()
{
	system("CLS");
	cout << "\n\n\tTic Tac Toe\n\n";
	cout << "Player 1 (X)  -  Player 2 (O)" << endl << endl;
	cout << endl;
	cout << "     |     |     " << endl;
	cout << "  " << square[1] << "  |  " << square[2] << "  |  " << square[3] << endl;
	cout << "_____|_____|_____" << endl;
	cout << "     |     |     " << endl;
	cout << "  " << square[4] << "  |  " << square[5] << "  |  " << square[6] << endl;
	cout << "_____|_____|_____" << endl;
	cout << "     |     |     " << endl;
	cout << "  " << square[7] << "  |  " << square[8] << "  |  " << square[9] << endl;
	cout << "     |     |     " << endl << endl;
}

i was working on tic tac toe, but i am stuck in the middle..
if you compiler, when player 1 presses 2, nothing happens....but works fine when you press 1....why the conditions after the first condition, not working!!
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
{
	char f, g,  e[10]={'o','1','2','3','4','5','6','7','8','9'};
	int a;
	int   c, d;
	for(a=1;(a<=9);a++)
	{
		int b;
		system("CLS");
		box();
if(a%2==1)
{
	cout<<"player 1 enter your num\n";
	cin>>b;
}

else 
{
	cout<<"player 2 enter you number\n";
cin>>c;	
}
if(b==1&&square[1]=='1')
square[1]='X';
else if(b==2&&square[2]=='2')
square[2]=='X';
else if(c==1&&square[1]=='1')
square[1]='O';
}



re-check this code
i see your problem.... the first player has a connection to the main. When the second and anyone els after that doesnt... i would also check to be sure that the program resets after every open and close.
i dont see, any problem in your given code..
please be a little detailed, as i am a beginner. and also i am not learning c++ 'legally' as i am only 15...its all training manuals, and pdf's//
thank you
i have changed the code to this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
for(a=1;(a<=9);a++)
	{
		int b;
		system("CLS");
		box();
if(a%2==1)
{
	cout<<"player 1 enter your num\n";
	cin>>b;
	if(b==1&&square[1]=='1')
square[1]='X';
	else if(b==2&&square[2]=='2'){
		square[2]=='X';}
}
else
{
	cout<<"player 2 enter you number\n";
cin>>c;	
}
}
getch();
return 0;
}

still no help!
Topic archived. No new replies allowed.