Sep 24, 2013 at 6:18pm UTC
#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;
}
Sep 24, 2013 at 6:31pm UTC
My advice tag your code and click <> on the right side of the input field.
Last edited on Sep 24, 2013 at 6:32pm UTC
Sep 24, 2013 at 6:58pm UTC
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 Sep 24, 2013 at 6:59pm UTC
Sep 24, 2013 at 7:05pm UTC
MarketAnarchist................this code not work right....plz check again
Sep 24, 2013 at 7:07pm UTC
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 Sep 24, 2013 at 7:09pm UTC
Sep 24, 2013 at 7:09pm UTC
earlier code is where ???????
Sep 24, 2013 at 7:12pm UTC
i deleted it because it was wrong.
Sep 24, 2013 at 7:13pm UTC
so what should i have to impliment their ?????
Sep 24, 2013 at 7:16pm UTC
and above doest not work......its boxes are totally crashed
Sep 24, 2013 at 7:19pm UTC
oh yea lol i was wondering why it looked like that. h/o ill take a look.
Sep 24, 2013 at 7:26pm UTC
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 Sep 24, 2013 at 7:30pm UTC
Sep 24, 2013 at 7:31pm UTC
friend u are doing best......but when i put some values then output is in wrong order
Last edited on Sep 24, 2013 at 7:32pm UTC
Sep 24, 2013 at 7:35pm UTC
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 Sep 24, 2013 at 7:37pm UTC
Sep 24, 2013 at 7:42pm UTC
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
Sep 24, 2013 at 7:44pm UTC
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 Sep 24, 2013 at 7:48pm UTC
Sep 24, 2013 at 7:48pm UTC
code is work......thanksssss