Question
I just need a help fixing this c++ program about the the tic tac toe game Write a program that allows two players to play
I just need a help fixing this c++ program about the the tic tac toe game Write a program that allows two players to play a game of tic-tac-toe. Use a two-dimensional c ha rarray with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that Displays the contents of the board array Allows player 1 to select a location on the board for an X. The program should ask the user to enter the row and column number. Allows player 2 to select a location on the board for an O. The program should ask the user to enter the row and column number. Determines whether a player has won, or a tie has occurred. If a player has won, the program should declare that player the winner and end. If a tie has occurred, the program should say so and end. Player 1 wins when there are three Xs in a row on the game board. The Xs can appear in a row, in a column, or diagonally across the board. A tie occurs when all of the locations on the board are full, but there is no winner.*/
#include stdafx.h #include
using namespace std; bool player1Won(); bool player1WonInARow(); bool player1WonInAColumn(); bool player1WonInDia();
bool player2Won(); bool player2WonInARow(); bool player2WonInAColumn(); bool player2WonInDia();
char tic_tac_toe[3][3]={*,*,*,*,*,*,*,*,*}; int player1R[5]; int player1C[5]; int player2R[4]; int player2C[4]; int countForP1R=0; int countForP2R=0;
int main() { int i=0; for(;i<9;i++) { int x,y,z,k; //display the contents of the board for(int a=0;a<3;a++) { for(int b=0;b<3;b++) { cout< //ask player one to select a location cout<< PLAYER1 Select a location by entering two number while << the first number, in the range of 0 to 2, stands << for the row of the loation and the second num, << in the range of 0 to 2, stands for the columns << of the location. Sperate two number by space. << ONLY LOCATIONS OCCUPIED BY * ARE AVALIABLE << ; cin>>x>>y; tic_tac_toe[x][y]=X; player1R[i]=x; player1C[i]=y; //display the contents of the board for(int a=0;a<3;a++) { for(int b=0;b<3;b++) { cout< //ask player two to select a location cout<< PLAYER2 Select a location by entering two number while << the first number, in the range of 0 to 2, stands << for the row of the loation and the second num, << in the range of 0 to 2, stands for the columns << of the location. Sperate two number by space. << ONLY LOCATIONS OCCUPIED BY * ARE AVALIABLE << ; cin>>z>>k; tic_tac_toe[z][k]=O; player2R[i]=z; player2C[i]=k; //determinate if player2 wins if(player2Won()==true) { cout< system(pause); return 0; } /////////////////////////////////////////////////////// ////////////determinate if player1 wins//////////////// /////////////////////////////////////////////////////// bool player1Won() { bool player1Won=false; if(player1WonInARow()==true) { cout< return player1Won; } bool player1WonInARow() { bool player1WonInARow=false; if(tic_tac_toe[0][0]==X&&tic_tac_toe[1][0]==X&&tic_tac_toe[2][0]==X) player1WonInARow=true; else if(tic_tac_toe[0][1]==X&&tic_tac_toe[1][1]==X&&tic_tac_toe[2][1]==X) player1WonInARow=true; else if(tic_tac_toe[0][2]==X&&tic_tac_toe[1][2]==X&&tic_tac_toe[2][2]==X) player1WonInARow=true; return player1WonInARow; } bool player1WonInAColumn() { bool player1WonInAColumn=false; if(tic_tac_toe[0][0]==X&&tic_tac_toe[0][1]==X&&tic_tac_toe[0][2]==X) player1WonInAColumn=true; else if(tic_tac_toe[1][0]==X&&tic_tac_toe[1][1]==X&&tic_tac_toe[1][2]==X) player1WonInAColumn=true; else if(tic_tac_toe[2][0]==X&&tic_tac_toe[2][1]==X&&tic_tac_toe[2][2]==X) player1WonInAColumn=true; return player1WonInAColumn; }
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