tic toe game problem.....need help

#include <iostream>
using namespace std;




int main()
{


char board[9];
int i=0;
while(i<9)
board[i++]=' ';
int tnumber=1;
char sym[2]={'0','X'};
while(tnumber<=9)
{
i=0;
cout<<" "<<char(45)<<" "<<char(45)<<" "<<char(45)<<" "<<"\n";
cout<<"| ";
while(i<9){
if(i==3 || i==6){
cout<<"\n";
cout<<" "<<char(45)<<" "<<char(45)<<" "<<char(45)<<" "<<"\n";
cout<<"\n| ";
}
cout<<board[i]<<" | ";
i++;
}
cout<<"\n";
cout<<" "<<char(45)<<" "<<char(45)<<" "<<char(45)<<" "<<"\n";
int row, col;
cout<<"Enter row and column (separate by space): ";
cin>>row>>col;
board[3*col+row]=sym[tnumber%2];

tnumber++;
}

return 0;
}

give not correct outputs
My advice tag your code and click <> on the right side of the input field.
Last edited on
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
#include<iostream>
using namespace std;

int main() {
	char board[9];
	int i=0;
	while(i<9) { //added
		board[i++]=' ';
		int tnumber=1;
		char sym[2]={'0','X'};
		while(tnumber<=9) {
			i=0;
			cout<<" "<<char(45)<<" "<<char(45)<<" "<<char(45)<<" "<<"\n";
			cout<<"| ";
				while(i<9){
					if(i==3 || i==6) {
						cout<<"\n";
						cout<<" "<<char(45)<<" "<<char(45)<<" "<<char(45)<<" "<<"\n";
						cout<<"\n| ";
					}
				cout<<board[i]<<" | ";
				i++;
				}
			cout<<"\n";
			cout<<" "<<char(45)<<" "<<char(45)<<" "<<char(45)<<" "<<"\n";
			int row, col;
			cout<<"Enter row and column (separate by space): ";
			cin>>row>>col;
			board[3*col+row]=sym[tnumber%2];
			tnumber++;
		}
	} //added
return 0;
}
Last edited on
MarketAnarchist................this code not work right....plz check again
it works right for me. perhaps try refreshing this page and try again. i changed some stuff since i first posted and what i posted the first time wasnt working. so perhaps you are using that earlier code.

*edit* i mean it isnt a full working version of the game of tic-tac-toe. it doesnt check for win conditions. but i was just assuming you hadn't implemented that yet.
Last edited on
earlier code is where ???????
i deleted it because it was wrong.
so what should i have to impliment their ?????
and above doest not work......its boxes are totally crashed
oh yea lol i was wondering why it looked like that. h/o ill take a look.
what u say ???????????
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
#include<iostream>
using namespace std;

int main() {
	char board[9] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',};
	int i=0;
	while(i<9) { //added
		board[i++]=' ';
		int tnumber=1;
		char sym[2]={'0','X'};
		while(tnumber<=9) {
			i=0;
			cout<<" "<<char(45)<<" "<<char(45)<<" "<<char(45)<<" "<<"\n";
			cout<<"| ";
				while(i<9){
					if(i==3 || i==6) {
						cout<<"\n";
						cout<<" "<<char(45)<<" "<<char(45)<<" "<<char(45)<<" "<<"\n";
						cout<<"\n| ";
					}
				cout<<board[i]<<" | ";
				i++;
				}
			cout<<"\n";
			cout<<" "<<char(45)<<" "<<char(45)<<" "<<char(45)<<" "<<"\n";
			int row, col;
			cout<<"Enter row and column (separate by space): ";
			cin>>row>>col;
			board[3*col+row]=sym[tnumber%2];
			tnumber++;
		}
	} //added
return 0;
}


tell me if this is more to your liking. you failed to initialize the array so it was printing out the elements using w/e junk you happened to have laying around in memory.
Last edited on
friend u are doing best......but when i put some values then output is in wrong order
Last edited on
yea sorry im a noob too, im just trying to give back to the community atleast as much as i take out.

ah ok yea i see that now. the simplest solution is to change line 27 from

cout<<"Enter row and column (separate by space): ";
to

cout<<"Enter column and row (separate by space): ";

=D but h/o ill take a look
Last edited on
friend when enter 1row and 1 column then output is in number 5 box....which is wrong..........i think i am wasting ur time.....thanks for help
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
#include<iostream>
using namespace std;

int main() {
	char board[9] = {' ',' ',' ',' ',' ',' ',' ',' ',};
	int i=0;
	while(i<9) {
		board[i++]=' ';
		int tnumber=1;
		char sym[2]={'0','X'};
		while(tnumber<=9) {
			i=0;
			cout<<" "<<char(45)<<" "<<char(45)<<" "<<char(45)<<" "<<"\n";
			cout<<"| ";
				while(i<9){
					if(i==3 || i==6) {
						cout<<"\n";
						cout<<" "<<char(45)<<" "<<char(45)<<" "<<char(45)<<" "<<"\n";
						cout<<"\n| ";
					}
				cout<<board[i]<<" | ";
				i++;
				}
			cout<<"\n";
			cout<<" "<<char(45)<<" "<<char(45)<<" "<<char(45)<<" "<<"\n";
			int row, col;
			cout<<"Enter row and column (separate by space): ";
			cin>>row>>col;
			board[3*row+col]=sym[tnumber%2]; //switched row and col around
			tnumber++;
		}
	}
return 0;
}


that's that problem solved. let me know if you encounter more. debugging other peoples code is good practice in a way that debugging my own isnt
Last edited on
code is work......thanksssss
welcome is you
Topic archived. No new replies allowed.