online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> void printGrid(); void winConditions(); void gameOver(); int main() { printf("Welcome to Tic Tac Toe simulator!\n"); int numGrid[9] = {-5,-5,-5,-5,-5,-5,-5,-5,-5}; char letterGrid[9] = {' ',' ',' ',' ',' ',' ',' ',' ',' '}; int p1, p2; bool gameOver = false; printGrid(p1, p2, letterGrid); while(!gameOver) { printf("Player 1, choose a quadrant to place your X. (1-9) "); scanf("%d", &p1); letterGrid[p1-1] = 'X'; numGrid[p1-1] = 1; printGrid(p1, p2, letterGrid); winConditions(numGrid); printf("Player 2, choose a quadrant to place your O. (1-9) "); scanf("%d", &p2); letterGrid[p2-1] = 'O'; numGrid[p2-1] = 2; printGrid(p1, p2, letterGrid); winConditions(numGrid); } } void printGrid(int p1, int p2, char letterGrid[]) { int j = 1; for(int i = 0; i < 9; i++) { printf("%c", letterGrid[i]); if(j % 3 == 0) { printf("\n"); } else { printf(" |"); } j++; } } void winConditions(int numGrid[]) { // Horizontal Wins Test for(int i = 0; i < 9; i+=3) { if(numGrid[i] + numGrid[i+1]+numGrid[i+2] == 3) { gameOverP1(); } else if(numGrid[i] + numGrid[i+1]+numGrid[i+2] == 6) { gameOverP2(); } } // Vertical Wins Test for(int i = 0; i < 3; i++) { if(numGrid[i] + numGrid[i+3]+numGrid[i+6] == 3) { gameOverP1(); } else if(numGrid[i] + numGrid[i+3]+numGrid[i+6] == 6) { gameOverP2(); } } // Horizontal NW-SE Test if(numGrid[0] + numGrid[4] + numGrid[8] == 3) { gameOverP1(); } else if(numGrid[0] + numGrid[4] + numGrid[8] == 6) { gameOverP2(); } // Horizontal NE-SW Test if(numGrid[2] + numGrid[4] + numGrid[6] == 3) { gameOverP1(); } else if(numGrid[2] + numGrid[4] + numGrid[6] == 6) { gameOverP2(); } } void gameOverP1() { printf("GAME OVER P1 WINS!"); exit(0); } void gameOverP2() { printf("GAME OVER P2 WINS!"); exit(0); }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue