What you need to do is break down the problem into manageable chunks. Lets start with declaring the 2D array and intializing it with all asterisks. Do you know how to do that?
Next you can make a simple print() function which loops through the array and prints its contents (i.e. prints the tic-tac board). Note that you will be calling this function in the loop.
Use a while loop, and set up a counter variable which you will increment in the loop. If the variable is even, its player 1's turn, otherwise its player 2's turn. The row and column # will be entered by the user, and you will simply put an 'X' or 'O' in that position depending on which players turn it is.
The while loop should end when the counter variable reaches 9 (can you see why?).
You should also make a separate function called checkForWin() which does what it says. This function should also be called in the loop, and will return a bool (true/false). If it returns a true, you know a player has won so you can break out of the loop.
What you need to do is break down the problem into manageable chunks. Lets start with declaring the 2D array and intializing it with all asterisks. Do you know how to do that?
I wouldn't be thrown off as much if it didn't say to use a two-D String array.
I'm not sure how to do it String wise. Let me make an attempt though so you know I'm trying.
The reason you are getting those errors is because the asterisks need to be surrounded by double quotes. Its a string array, which means its hold strings (i.e. every individual element is a string), and we know that a string literal must be surrounded by double quotes.
Another thing is that you are trying to initialize a 1 dimensional array of size 9. Remember, that we have a two dimensional array of size 3 by 3. What this mean is that we have actually declared 3 arrays, each of size 3. Thus, they would be initialized like this:
Notice that the first number of the brackets represents which number array which are referring to (thats what I've commented above). The second dimension gives us the element index within that array.
So tictac[1][2] means go to the first array (array[1]), then the second index in that array. I've represented that below:
Sorry I'm a bit slow with this one. We just finished learning about arrays and 2D ones are very confusing concepts for me, but I'll continue doing my best to understand.
Your suggestion was not very clever. What if the OP chose to have a board or 5x5, or 7x7 instead? I would not recommend that kind of initialization. A manual initialization is always better for all cases :
1 2 3 4 5
string ticTac[ROWS][COLS];
for (int i = 0; i < ROWS; i++)
for (int j = 0; j < COLS; j++)
ticTac[i][j] = "*";
Those are new errors. They have to do with passing the array to the function I made.
I've only ever passed doing a single array.
When passing 2D arrays, the second dimension must have a bound in it. So it should look like this:
1 2 3 4 5
void print(int arr[][COLS])
{
}
@closed account: I understand that, but I think for the purposes of the assignment at hand (which explicitly states 3 by 3, and not a variable size), it is sufficient.
Hopefully finish at least step d as long as one of you guys are still online. Sorry I'm not very self-sufficient. I thought after how good I did on the number analysis program myself this wouldn't be any issue, but this exercise is killing me.
I take that back. It says COLS for the function prototype was not declared in the scope, so it's not the same, but an error didn't go away. The other one did though.