Skip to main content
edited tags
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
Tweeted twitter.com/#!/StackCodeReview/status/615140461339111424
Rollback to Revision 2
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Edit One:

Thank you everyone for all of your responses and suggestions. All of you have been very helpful! I'm in the midst of redoing the program and incorporating many of the suggestions posted. I will make another edit to my post with the updated code soon! Edit Two:

I've been trying to rewrite this code for about 2 hours. A lot of what I've changed has been successful however I am stumped for one section I'm trying to write. My issue is that statements near the end of my while-loop are executing before statements above it. Here is the code:

int startGame() { bool winner = false; printf("\n\nHere is your playing board. Player One is Os and Player Two is Xs\n"); printf("Entering a number 1-9 (then pushing enter) as shown below will use\nthe current Player's turn in that location.\n"); printBoard(); int j=0; char token; char turn; do { scanf("%1c",&turn); token = (j % 2 == 0) ? 'O' : 'X'; if (turn=='1') { board[0][0] = token; printBoard(); } if (turn=='2') { board[0][1] = token; printBoard(); } if (turn=='3') { board[0][2] = token; printBoard(); } if (turn=='4') { board[1][0] = token; printBoard(); } if (turn=='5') { board[1][1] = token; printBoard(); } if (turn=='6') { board[1][2] = token; printBoard(); } if (turn=='7') { board[2][0] = token; printBoard(); } if (turn=='8') { board[2][1] = token; printBoard(); } if (turn=='9') { board[2][2] = token; printBoard(); } printf("\n%d",j); printf(" %c",token); } while (j<9 && winner == false); return 0; } 

The 2 printf statements at the end execute before I have time to input a value for turn. If I continue entering values in the program, j increments twice making token's value always 'X'. I feel like I'm missing something very obvious ._.

Edit One:

Thank you everyone for all of your responses and suggestions. All of you have been very helpful! I'm in the midst of redoing the program and incorporating many of the suggestions posted. I will make another edit to my post with the updated code soon! Edit Two:

I've been trying to rewrite this code for about 2 hours. A lot of what I've changed has been successful however I am stumped for one section I'm trying to write. My issue is that statements near the end of my while-loop are executing before statements above it. Here is the code:

int startGame() { bool winner = false; printf("\n\nHere is your playing board. Player One is Os and Player Two is Xs\n"); printf("Entering a number 1-9 (then pushing enter) as shown below will use\nthe current Player's turn in that location.\n"); printBoard(); int j=0; char token; char turn; do { scanf("%1c",&turn); token = (j % 2 == 0) ? 'O' : 'X'; if (turn=='1') { board[0][0] = token; printBoard(); } if (turn=='2') { board[0][1] = token; printBoard(); } if (turn=='3') { board[0][2] = token; printBoard(); } if (turn=='4') { board[1][0] = token; printBoard(); } if (turn=='5') { board[1][1] = token; printBoard(); } if (turn=='6') { board[1][2] = token; printBoard(); } if (turn=='7') { board[2][0] = token; printBoard(); } if (turn=='8') { board[2][1] = token; printBoard(); } if (turn=='9') { board[2][2] = token; printBoard(); } printf("\n%d",j); printf(" %c",token); } while (j<9 && winner == false); return 0; } 

The 2 printf statements at the end execute before I have time to input a value for turn. If I continue entering values in the program, j increments twice making token's value always 'X'. I feel like I'm missing something very obvious ._.

added 2530 characters in body
Source Link
SuperGoA
  • 373
  • 3
  • 7

Thank you everyone for all of your responses and suggestions. All of you have been very helpful! I'm in the midst of redoing the program and incorporating many of the suggestions posted. I will make another edit to my post with the updated code soon! Edit Two:

Thank you everyoneI've been trying to rewrite this code for all of your responses and suggestionsabout 2 hours. AllA lot of you havewhat I've changed has been very helpful!successful however I am stumped for one section I'm intrying to write. My issue is that statements near the midstend of redoingmy while-loop are executing before statements above it. Here is the program and incorporating many ofcode:

int startGame() { bool winner = false; printf("\n\nHere is your playing board. Player One is Os and Player Two is Xs\n"); printf("Entering a number 1-9 (then pushing enter) as shown below will use\nthe current Player's turn in that location.\n"); printBoard(); int j=0; char token; char turn; do { scanf("%1c",&turn); token = (j % 2 == 0) ? 'O' : 'X'; if (turn=='1') { board[0][0] = token; printBoard(); } if (turn=='2') { board[0][1] = token; printBoard(); } if (turn=='3') { board[0][2] = token; printBoard(); } if (turn=='4') { board[1][0] = token; printBoard(); } if (turn=='5') { board[1][1] = token; printBoard(); } if (turn=='6') { board[1][2] = token; printBoard(); } if (turn=='7') { board[2][0] = token; printBoard(); } if (turn=='8') { board[2][1] = token; printBoard(); } if (turn=='9') { board[2][2] = token; printBoard(); } printf("\n%d",j); printf(" %c",token); } while (j<9 && winner == false); return 0; } 

The 2 printf statements at the suggestions posted.end execute before I will make another edithave time to my post withinput a value for turn. If I continue entering values in the updated code soon!program, j increments twice making token's value always 'X'. I feel like I'm missing something very obvious ._.

Thank you everyone for all of your responses and suggestions. All of you have been very helpful! I'm in the midst of redoing the program and incorporating many of the suggestions posted. I will make another edit to my post with the updated code soon!

Thank you everyone for all of your responses and suggestions. All of you have been very helpful! I'm in the midst of redoing the program and incorporating many of the suggestions posted. I will make another edit to my post with the updated code soon! Edit Two:

I've been trying to rewrite this code for about 2 hours. A lot of what I've changed has been successful however I am stumped for one section I'm trying to write. My issue is that statements near the end of my while-loop are executing before statements above it. Here is the code:

int startGame() { bool winner = false; printf("\n\nHere is your playing board. Player One is Os and Player Two is Xs\n"); printf("Entering a number 1-9 (then pushing enter) as shown below will use\nthe current Player's turn in that location.\n"); printBoard(); int j=0; char token; char turn; do { scanf("%1c",&turn); token = (j % 2 == 0) ? 'O' : 'X'; if (turn=='1') { board[0][0] = token; printBoard(); } if (turn=='2') { board[0][1] = token; printBoard(); } if (turn=='3') { board[0][2] = token; printBoard(); } if (turn=='4') { board[1][0] = token; printBoard(); } if (turn=='5') { board[1][1] = token; printBoard(); } if (turn=='6') { board[1][2] = token; printBoard(); } if (turn=='7') { board[2][0] = token; printBoard(); } if (turn=='8') { board[2][1] = token; printBoard(); } if (turn=='9') { board[2][2] = token; printBoard(); } printf("\n%d",j); printf(" %c",token); } while (j<9 && winner == false); return 0; } 

The 2 printf statements at the end execute before I have time to input a value for turn. If I continue entering values in the program, j increments twice making token's value always 'X'. I feel like I'm missing something very obvious ._.

added 281 characters in body
Source Link
SuperGoA
  • 373
  • 3
  • 7
Loading
deleted 1 character in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
Source Link
SuperGoA
  • 373
  • 3
  • 7
Loading