I`m trying to program this tic tac toe game, I have the screan printing like I want it to, but I don`t know how to take the user`s input and change the numbers in the array to an "X" or "O" depending on the user`s input, and upgrade the grid, I want to have player1, and player2, "X" for player1 and "O" for player two.
Can anybody help me?
#include <iostream>
#include <iomanip>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::setw;
//global variables
const int row = 3; //size of array
const int column = 3; // size of array
void ticTacToe(const string ticTacToe[][column]); //Function prototypes
// program execution begins
int main()
{
int player1;
int player2;
string ticTac[row][column] = {{"1","2","3"}, {"4","5","6"}, {"7","8","9"}}; //number display for rows and columns
cout << "Welcome to the tic tac toe game "<<endl << endl; // welcome message
ticTacToe( ticTac ); // function call
return 0;
}
//Function ticTacToe
void ticTacToe(const string ticTacToe[][column])
{
cout << setw(5)<<"|"<<setw(5)<< "|" <<endl;
//for loop-continuation condition and increment
for (int i = 0; i <row; i ++)
{
for (int j = 0; j < column; j++)
//check to output '|' only in between the numbers, not at the end
if ( j < column - 1)
{
cout << setw(3)<< ticTacToe[i][j] << setw(2)<<"|";
}
else
cout << setw(3)<<ticTacToe[i][j];
cout << endl;
// check to make sure the horizontal line in only printed in between
// the 3 rows, not on the bottom fo the picture
if ( i < row -1)
{
cout << "____|____|____"<<endl;
cout << setw(5) << "|" << setw(5) << "|" << endl;
}
else
cout << setw(5) << "|" << setw(5) << "|" << endl;
}
}