### tic tac toe problem

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253`` ``````#include #include 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!!
 ``123456789101112131415161718192021222324252627`` ``````{ 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:
 ``1234567891011121314151617181920212223`` ``````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.