> According to the OP's teachers instructions, the user should be entering a row and column #. The 'X' or 'O' should be put at that position. In other words, we need two inputs from the user to get the position.
Oh, I get it. This is too easy, and can't be easier.
#include <iostream>
usingnamespace std;
constint ROWS=3;
constint COLS=3;
void printBoard(string ticTac[][COLS]);
void userInput(string ticTac[][COLS]);
int main()
{
string ticTac[ROWS][COLS]= {"*","*","*",
"*", "*","*",
"*","*","*"
};
printBoard(ticTac);
userInput(ticTac);
return 0;
}
void printBoard(string ticTac[][COLS])
{
for (int i = 0; i < ROWS; i++)
{
cout << '\t';
for (int j = 0; j < COLS; j++)
{
cout << ticTac[i][j] << ' ';
}
cout << endl;
}
}
void userInput(string ticTac[][COLS])
{
int positionRow;
int positionCol;
do
{
cout << "Player X, please enter what row and column you'd like to place your X on." << endl;
cin >> ticTac[positionRow][positionCol];
if(positionRow!=1 || 2 || 3 || positionCol!=1 || 2 || 3)
{
cout << "You must enter a row that's between 1 and 3 and a column between 1 and 3." << endl;
}
}
while(positionRow!=1 || 2 || 3 || positionCol!=1 || 2 || 3);
do
{
cout << "Player O, please enter what row and column you'd like to place your X on." << endl;
cin >> ticTac[positionRow][positionCol];
if(positionRow!=1 || 2 || 3 || positionCol!=1 || 2 || 3)
{
cout << "You must enter a row that's between 1 and 3 and a column between 1 and 3." << endl;
}
}
while(positionRow!=1 || 2 || 3 || positionCol!=1 || 2 || 3);
}
When I try to enter a row or column in my program, the whole thing shuts down, so I must've done something wrong.
Well, step back. The more you go further, the more things will very likely go wrong.
Remove the input validation part.
Remove all do-while loop stuff
Don't use cin to make changes to an array element directly.
cin >> ticTac[positionRow][positionCol];
Prompt the user to input positionRow & positionCol. After you are sure the user has input all of them, use them to make changes to a specific board element. And display the board after the action is done.
I'm not sure how you'd use them to make changes to the specific board element, but I do believe I have an idea to do the input. It's just not working for some reason.
I also believe I can do the board. I assume I just call my print function in the userInput function.
You only need to display the function you are working on, not your full code. Anyway, do as what I say. You at least need valid positionRow, positionCol before you can do anything.
The ideal program output should look like this :
Player X :
Enter row #: 2
Enter column # 2
* * *
* X *
* * *