#include #include #include using namespace std; string displayBoard(string board[9]); int main() { string board[9]; // tic tac toe, top row 0 thru 2, middle row 3 thru 5, bottom row 6 thru 8 int position = 0; // player's position bool gameOver = false; // loop variable bool validMove = false; // determines when valid move is inputted // initializing board with blank spaces for (int i = 0; i < 9; i++) { board[i] = " "; } while (!gameOver) { validMove = false; while (!validMove) { cout << "Enter your position: "; cin >> position; if (board[position] == " " && position >= 0 && position <= 8) { validMove = true; board[position] = "x"; } else { cout << "That position is already occupied." << endl; cout << displayBoard(board) << endl; } } cout << displayBoard(board) << endl; } system("pause"); return 0; }// end of main string displayBoard(string board[9]) { string str = ""; for (int i = 0; i < 9; i++) { if (i == 0) { str = str + "|" + board[i]; } else if (i == 2 || i == 5) { str = str + board[i] + "|\n|"; } else if (i == 8) { str = str + board[i] + "|\n"; } else { str = str + board[i]; } } return str; }// end of displayBoard