ran once but does not display gameboard and I'm 100% sure it's something to do with my int main. I really struggle with calling functions together..... (it's at very bottom)
Code:#include <stdio.h> void info() { printf("TIC-TAC-TOE\nWritten by MEEEE\n"); printf("Your Symbol 'x'"); printf("Computer Symbol 'o'"); } /*initialize board*/ void init(char cell[]) { int i; for (i=0; i<9; i++) cell[i] = ' '; } /*print gameboard */ void gameBoard(char cell[]) { printf("\n %c | %c | %c \n", cell[0], cell[1], cell[2]); printf("---|---|---\n"); printf(" %c | %c | %c \n", cell[3], cell[4], cell[5]); printf("---|---|---\n"); printf(" %c | %c | %c \n\n", cell[6], cell[7], cell[8]); } /*player moves*/ void userMove(char *cell) { int i = 0; do { printf("Your Move (0-8): "); scanf("%d", &i); } // Here should also check if cell already filled while ( i < 0 || i > 8 ); cell[i]='x'; } void computerMove(char *cell) { // Here should play smart, for now just choose first empty cell int i; for (i=0;i!=9;i++) { if (cell[i] == ' ') { cell[i] = 'o'; return; } } } char checkWinner(char* cell) { //diagonals if (cell[0] != ' ') if ((cell[0] == cell[4]) && (cell[0] == cell[8])) return cell[0]; if (cell[2] != ' ') if ((cell[2] == cell[4]) && (cell[2] == cell[6])) return cell[2]; // horizontals if (cell[0] != ' ') if ((cell[0] == cell[1]) && (cell[0] == cell[2])) return cell[3]; if (cell[3] != ' ') if ((cell[3] == cell[4]) && (cell[3] == cell[5])) return cell[0]; if (cell[6] != ' ') if ((cell[6] == cell[7]) && (cell[6] == cell[8])) return cell[6]; // verticals if (cell[0] != ' ') if ((cell[0] == cell[3]) && (cell[0] == cell[6])) return cell[0]; if (cell[1] != ' ') if ((cell[1] == cell[4]) && (cell[1] == cell[7])) return cell[1]; if (cell[2] != ' ') if ((cell[2] == cell[5]) && (cell[2] == cell[8])) return cell[2]; return ' '; } bool_gameIsOver(char *cell) { char winner; winner = checkWinner(cell); if (winner=='o') printf("Computer win !\n"); else if (winner=='x') printf("You win !\n"); return winner != ' '; } int main() { int false; int bool_continue; int _continue; char cell[9]; bool_continue; info(); init(cell); _continue = true; while(_continue) { computerMove(cell); gameBoard(cell); if (gameIsOver(cell)) _continue = false; else { userMove(cell); gameBoard(cell); if (gameIsOver(cell)) _continue = false; } } return 0; }



1Likes
LinkBack URL
About LinkBacks



I have all the functions...ok.....but now I need help constructing the int main...which I really have no clue to begin with...someone help me.