Note that there are some explanatory texts on larger screens.

plurals
  1. POTictactoe c program error with main function
    primarykey
    data
    text
    <p>I'm creating a simple tictactoe game in C. However I keep getting this error in my main function, I don't know what expected expression it wants before my else statement. How the program works is I get symbols from both players, an they begin the game.</p> <p><strong>Error:</strong></p> <pre><code>tictac.c: In function ‘main’: tictac.c:31: error: expected expression before ‘else’ tictac.c: At top level: tictac.c:49: warning: conflicting types for ‘print’ tictac.c:30: warning: previous implicit declaration of ‘print’ was here tictac.c:63: error: conflicting types for ‘check’ tictac.c:63: note: an argument type that has a default promotion can’t match an empty parameter name list declaration tictac.c:29: error: previous implicit declaration of ‘check’ was here tictac.c:89: warning: conflicting types for ‘move’ tictac.c:28: warning: previous implicit declaration of ‘move’ was here </code></pre> <p><strong>Code:</strong> </p> <pre><code>char board[3][3]; int main(void) { int first; char player1, player2; printf("Player 1: Choose your symbol: \n"); player1 = getchar(); printf("Player 2: Choose your symbol: \n"); player2 = getchar(); int i=0; int win; char turn; while(win == 0) { if((i%2) == 0) turn = player1; move(player1); win = check(player1); print(); else turn = player2; move(player2); i++; } if (i == 8) printf("its a tie"); else printf("the winner is %c", turn); return 0; } /*printing the board that takes in a placement int*/ void print(void) { int r; printf("\n"); for (r = 0; r &lt; 3; r++){ printf(" %c | %c | %c \n" , board[r][0], board[r][2], board[r][3]); if (r != 2) printf("___________\n"); } printf("\n"); return; } /*check to see if someone won*/ int check(char player) { int r, c; for ( r = 0 ; r &lt;3 ; r++) { if ((board[r][0] == player) &amp;&amp; (board[r][1] == player) &amp;&amp; (board[r][2] == player)) return 1; } for ( c = 0 ; c &lt;3 ; c++) { if ((board[0][c] == player) &amp;&amp; (board[1][c] == player) &amp;&amp; (board[2][c] == player)) return 1; } if((board[0][0] == player) &amp;&amp; (board[1][1] == player) &amp;&amp; (board[2][2] == player)) return 1; if((board[0][2] == player) &amp;&amp; (board[1][1] == player) &amp;&amp; (board[2][0] == player)) return 1; return 0; } void move(char player) { int place; printf("player1, enter placement: \n"); scanf("%d", &amp;place); if (place == 1) board[0][0] = player; else if (place == 2) board[0][1] = player; else if (place == 3) board[0][2] = player; else if (place == 4) board[1][0] = player; else if (place == 5) board[1][1] = player; else if (place == 6) board[1][2] = player; else if (place == 7) board[2][0] = player; else if (place == 8) board[2][1] = player; else if (place == 9) board[2][2] = player; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload