Question
Im trying to write a c++ program for tic tac toe, and it keep looping and ending the program everytime i try to run it.
Im trying to write a c++ program for tic tac toe, and it keep looping and ending the program everytime i try to run it. I want the players to be able to make each move, Here's the code that I have so far.
#include
int main() { int counter = 0; bool isGameOver = true; while(isGameOver) { counter++; Player1(); TTT[Player1_Rows][Player1_Cols] = 1; if (TTT[0][0] == 1 && TTT[0][1] == 1 && TTT[0][2] == 1) isGameOver = false; else if (TTT[1][0] == 1 && TTT[1][1] == 1 && TTT[1][2] == 1) isGameOver = false; else if (TTT[2][0] == 1 && TTT[2][1] == 1 && TTT[2][2] == 1) isGameOver = false; //Across else if (TTT[0][0] == 1 && TTT[1][1] == 1 && TTT[2][2] == 1) isGameOver = false; else if (TTT[0][2] == 1 && TTT[1][1] == 1 && TTT[2][0] == 1) isGameOver = false;
if (!isGameOver) { cout << " Player 1 Won!!!!!" << endl; break; } Player2(); TTT[Player2_Rows][Player2_Cols] = 2;
if (TTT[0][0] == 2 && TTT[0][1] == 2 && TTT[0][2] == 2) isGameOver = false; else if (TTT[1][0] == 2 && TTT[1][1] == 2 && TTT[1][2] == 2) isGameOver = false; else if (TTT[2][0] == 2 && TTT[2][1] == 2 && TTT[2][2] == 2) isGameOver = false; else if (TTT[0][0] == 2 && TTT[1][1] == 2 && TTT[2][2] == 2) isGameOver = false; else if (TTT[0][2] == 2 && TTT[1][1] == 2 && TTT[2][0] == 2) isGameOver = false;
if (!isGameOver) { cout << " Player 2 Won!!!!!" << endl; break; } cout << "..............."; } cout << " Game Over in " << counter << " Moves" << endl; return 0; }
void Player1() { srand(time(NULL)); Player1_Rows = rand() % 3; Player1_Cols = rand() % 3; }
void Player2() { srand(time(NULL)); Player2_Rows = rand() % 3; Player2_Cols = rand() % 3; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started