### Tic Tac Toe Game 2D Array

My code runs, but it doesn't print out anything in the board. I'm pretty sure i have done a couple of things wrong, and if someone could point me in the right direction, that would be great.. Thanks for any help!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230`` ``````#include #include using namespace std; void drawBoard(char board[][3]); char checkWinner3by3(char board[][3]); . // // DO NOT MODIFY THE MAIN FUNCTION // int main() { // This array of chars represents the game board, and it holds the content // of each space. By default all spaces are set to a blank space. char board[3][3] = {{' ',' ',' '},{' ',' ',' '},{' ',' ',' '}}; // The current player. Because X plays first, initialize to X char player = 'X'; // The winner. either 'X', 'O', or 't' if it's a tie. // Or a blank space if the game has not finished. char winner = ' '; // These variables will hold the number of the row and column selected // by the players. int row; int column; // boolean variables used to verify if the move is valid. bool is_move; bool is_row; bool is_column; cout<<"************ TIC TAC TOE ************\n"; // The game loops again and again until the game is over while(winner == ' ') { //set the boolean variables back to false for a new turn. is_move = false; is_row = false; is_column = false; //draw the board. drawBoard(board); // If the game is not yet over show who`s the next player to move cout << "Player "; if(player == 'X') { cout << 1; } else { cout << 2; } cout << "'s turn:" << endl; // Loop until the player selects a valid space for their move is_move = false; while(!is_move) { // Loop until the player selects a valid row // Assume the user inputs a valid integer is_row = false; while(!is_row) { cout << "Row: "; cin >> row; if(row == 1 || row == 2 || row == 3) { is_row = true; } else { cout << endl << "Invalid row!" << endl; } } // end of input row loop // Loop until the player selects a valid column // Assume the user inputs a valid integer is_column = false; while(!is_column) { cout << "Column: "; cin >> column; if(column == 1 || column == 2 || column == 3) { is_column = true; } else { cout << endl << "Invalid column!" << endl; } } // end of input column loop // If the space is empty, mark the chosen space and swich players if(board[row-1][column-1] == ' ') { // Mark the space and end the player's turn board[row-1][column-1] = player; is_move = true; // Switch to the other player if(player == 'X') { player = 'O'; } else { player = 'X'; } } // end of marking space and changing players // If the space is occupied else { cout<<"The selected space is occupied!" << endl; cout << "Select a different space:" << endl << endl; drawBoard(board); } } // end of player's move loop cout << endl; // for nice output formatting //check if the player won. winner = checkWinner3by3(board); //If there's a winner if(winner == 'X' || winner == 'O') { drawBoard(board); //Display congratulations message cout<<"Congratulations! Player "; if(winner == 'X') { cout << 1; } else { cout << 2; } cout<<" is the winner!"<
Topic archived. No new replies allowed.