1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <iostream>
#include <iomanip>
using namespace std;
const gRow = 3;
const gCol = 3;
void showGrid(char grid[][gCol], int);
int changeValue(int, int);
int main()
{ char grid[gRow][gCol] = {{'*', '*', '*'},
{'*', '*', '*'},
{'*', '*', '*'}};
int rows, cols;
int el = 1;
cout << " TIC TAC TOE" << endl;
cout << "Player One: X Player Two: O\n" << endl;
do {
showGrid(grid, gRow);
cout << "Player 1, Enter the row and column:";
cin >> rows >> cols;
changeValue(rows, cols);
grid[rows][cols] = 'X';
showGrid(grid, gRow);
cout << "Player 2, Enter the row and column:";
cin >> rows >> cols;
grid[rows][cols] = 'O';
}
while(el = 1);
return 0;
}
void showGrid(char array[][gCol], int numRows)
{
for (int row = 0; row < numRows; row++)
{ for (int col = 0; col < gCol; col++)
{
cout << setw(2) << array[row][col] << " ";
}
cout << endl;
}
}
int changeValue(int num1, int num2)
{
switch (num1)
{
case 1: num1 = 0;
break;
case 2: num1 = 1;
break;
case 3: num1 = 2;
}
switch (num2)
{
case 1: num2 = 0;
break;
case 2: num2 = 1;
break;
case 3: num2 = 2;
}
return num1, num2;
}
|