void userInput(string ticTac[][COLS])
{
int positionRow;
int positionCol;
cout << "Please enter a row and a column player X." << endl;
cin >> positionRow;
cin >> positionCol;
ticTac[positionRow][positionCol] = "X";
printBoard(ticTac);
cout << "Please enter a row and a column player O." << endl;
cin >> positionRow;
cin >> positionCol;
ticTac[positionRow][positionCol] = "O";
printBoard(ticTac);
cout << "Please enter a row and a column player X." << endl;
cin >> positionRow;
cin >> positionCol;
ticTac[positionRow][positionCol] = "X";
printBoard(ticTac);
cout << "Please enter a row and a column player O." << endl;
cin >> positionRow;
cin >> positionCol;
ticTac[positionRow][positionCol] = "O";
printBoard(ticTac);
cout << "Please enter a row and a column player X." << endl;
cin >> positionRow;
cin >> positionCol;
ticTac[positionRow][positionCol] = "X";
cout << "Please enter a row and a column player O." << endl;
cin >> positionRow;
cin >> positionCol;
ticTac[positionRow][positionCol] = "O";
}
But I feel like I'll lose points for this one if I don't make sure that the user's can't put their "markers" over each other (as in X and O).
You only need a piece of code for the player X, and a piece of code for the player O. If you want to repeat, use a while loop. But we will talk about that later.
Your example is still a failure. Make sure your program output look exactly like this :
Player X :
Enter row #: 2
Enter column #: 2
* * *
* X *
* * *
Player O :
Enter row #: 3
Enter column #: 2
* * *
* X *
* O *
cout << "Please enter a row and a column player X." << endl;
cin >> positionRow;
cin >> positionCol;
ticTac[positionRow][positionCol] = "X";
printBoard(ticTac);
while("X") // Prompt the player X
{
// Your code
// If anything fails, display an error message and continue the loop
if(ticTac[positionRow][positionCol] == "*")
ticTac[positionRow][positionCol] = "X";
else
{
cout << "That spot has been already chosen!\n\n";
continue;
}
displayBoard(ticTac);
break;
}
while("O") // Prompt the player O
{
// Your code
// If anything fails, display an error message and continue the loop
if(ticTac[positionRow][positionCol] == "*")
ticTac[positionRow][positionCol] = "O";
else
{
cout << "That spot has been already chosen!\n\n";
continue;
}
displayBoard(ticTac);
break;
}
Well if they try to put a character over a character that's already there, and it says someone else has put theirs there, how will we prompt them so they enter until they do it correctly?