Lab 4: Tic-Tac-Toe, this time with Functions!
In this week's lab you will once again write a C program to display a Tic-Tac-Toe board and allow making moves. This time, however, you will be using functions! It is okay to use your lab 3 as a starting point.
The execution of the finished program should look like what is shown below. (User input is shown in bold, though in your program it will not be bold.)
Welcome to Tic-Tac-Toe.
--------------
Board is:
. . . 1 2 3
. . . 4 5 6
. . . 7 8 9
Please enter the destination and character to be placed: 5X
--------------
Board is:
. . . 1 2 3
. X . 4 5 6
. . . 7 8 9
Please enter the destination and character to be placed: 5X
Stage 1 (1 point):
Check to make sure you are not using global variables. You are not allowed to use global variables in this lab!
Create 9 variables to represent the board, a userInput variable, and a moveNumber variable.
Then write a function to display the board. Call this function in main whenever the board needs to be displayed.
Stage 2 (1 point):
Write a function that receives user input.
Create a loop in main() that loops until each board position has been changed. (Note - if you don't prevent players from overwriting each other's moves it is possible to go more than 9 times without changing every position!)
Display the move number each time through the loop. The moves made by the players need to show up on the board.
Stage 3 (Extra Credit) (1 point):
Create a boolean checkForWin(...) function that itself utilizes a boolean allThreeAreTheSame(...) function. Have the main() loop utilize these functions to determine if a player has won.
Notes:
Keep in mind that this is a team effort so you should agree with your partner on what you are going to do before you start typing. The partner who is typing is the "driver" and the partner watching is the "navigator." Be sure to switch roles every 10 to 15 minutes, to foster a deep understanding of the code for both partners. The navigator should be watching for syntax errors and verifying the correctness of the code you're writing.
It will speed things up for you if you keep a window open for editing and have a separate window open for compiling and running your program. Remember that windows are resizeable!
Submission:
You should work with a partner for a grade. Only one submission per group is necessary, but be sure to include your name if you work alone, or both people's names if you worked with a partner.
You should submit the lab to the Blackboard at the end of the lab session, by 50 minutes after the hour.