I am practicing my arrays, and I am trying to make a number/letter tic-tac-toe game. Here is my code:
#include<iostream>
using namespace std;
char board[3][3];
char letterNum;
void displayBoard();
void move();
void displayBoard()
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
board[0][0] = '1';
board[0][1] = '2';
board[0][2] = '3';
board[0][3] = '4';
board[1][0] = '5';
board[1][1] = '6';
board[1][2] = '7';
board[1][3] = '8';
board[2][0] = '9';
board[2][1] = 'A';
board[2][2] = 'B';
cout << board[i][j];
if (j < 2)
cout << '|';
else
cout << endl;
}
if (i < 2)
cout << "-----" << endl;
}
}
int main()
{
displayBoard();
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
board[i][j] = ' ';
}
move();
system("PAUSE");
return 0;
}
void move()
{
cout << "Enter a number or letter that you want to move." << endl;
cin >> letterNum;
switch (letterNum)
{
case '1':
board[0][0] = 'X';
case '2':
board[0][1] = 'X';
case '3':
board[0][2] = 'X';
case '4':
board[0][3] = 'X';
case '5':
board[1][0] = 'X';
case '6':
board[1][1] = 'X';
case '7':
board[1][2] = 'X';
case '8':
board[1][3] = 'X';
case '9':
board[2][0] = 'X';
case 'A':
board[2][1] = 'X';
case 'B':
board[2][2] = 'X';
}
displayBoard();
}
Thank you.