Tic Tac Toe with a 1 Dimensional Array
Video Summary: https://youtu.be/orX6bFQA44M
The goal of this exercise is to create a simple tic tac toe loop using an array of size 9. The numeric positions in the array would be as follows:
0|1|2 ------ 3|4|5 ------ 6|7|8
To implement the game loop:
- Create a character array of size 9 and initialize all the positions to blank with ' '
- Create a void function named printGrid and pass it the character array. It should print the game grid every turn so players can see what moves are available
- Create a loop for the game. Since there are 9 spaces on the grid, it will need to loop 9 times
- Prompt the user for an array position. If it is an even turn, place an x in that position. If it is an odd turn, place an o
- If the position was already filled (is not ' '), prompt the user again
You may assume the user will only enter valid input between 0 and 9. You do not need to try to determine a winner.
When you are finished, your output might look like this;
| | ------ | | ------ | | Enter the array position for x 0 x| | ------ | | ------ | | Enter the array position for o 1 x|o| ------ | | ------ | | Enter the array position for x 2 x|o|x ------ | | ------ | | Enter the array position for o 3 x|o|x ------ o| | ------ | | Enter the array position for x 4 x|o|x ------ o|x| ------ | | Enter the array position for o 5 x|o|x ------ o|x|o ------ | | Enter the array position for x 6 x|o|x ------ o|x|o ------ x| | Enter the array position for o 7 x|o|x ------ o|x|o ------ x|o| Enter the array position for x 8 x|o|x ------ o|x|o ------ x|o|x