Tic Tac Toe
Tic Tac Toe
Tic Tac Toe
char convert(char&);
int main ()
{
int ire = 9;
int moves;
char irel;
while (ire > 0)
{cin >> irel; cout << ire; ire--;}
char tic[9];
int nah = 8;
while (nah >= 0)
{
tic[nah] = '*';
nah--;
}
cout << tic[0] << tic[1] << tic[2] << endl << tic[3] << tic[4] << tic[5] << endl << tic[6] << tic[7]
<< tic[8] << endl << endl;
cin >> x;
cin >> y;
cin >> move;
if (y == 1)
{
if (move == 'A'){t = 0; tic[t] = 'O';}
else if (move == 'B'){t = 1; tic[t] = 'O';}
else if (move == 'C'){t = 2; tic[t] = 'O';}
else if (move == 'D'){t = 3; tic[t] = 'O';}
else if (move == 'E'){t = 4; tic[t] = 'O';}
else if (move == 'F'){t = 5; tic[t] = 'O';}
else if (move == 'G'){t = 6; tic[t] = 'O';}
else if (move == 'H'){t = 7; tic[t] = 'O';}
else if (move == 'I'){t = 8; tic[t] = 'O';}
}
else if (y == 2)
{
if (move == 'A'){t = 0; tic[t] = 'X';}
else if (move == 'B'){t = 1; tic[t] = 'X';}
else if (move == 'C'){t = 2; tic[t] = 'X';}
else if (move == 'D'){t = 3; tic[t] = 'X';}
else if (move == 'E'){t = 4; tic[t] = 'X';}
else if (move == 'F'){t = 5; tic[t] = 'X';}
else if (move == 'G'){t = 6; tic[t] = 'X';}
else if (move == 'H'){t = 7; tic[t] = 'X';}
else if (move == 'I'){t = 8; tic[t] = 'X';}
}
moves--;
}
char convert(char& a)
{
int A = 0, B = 1, C = 2, D = 3, E = 4, F = 5, G = 6, H = 7, I = 8;
if (a == 'A'){return A;}
else if (a == 'B'){return B;}
else if (a == 'C'){return C;}
else if (a == 'D'){return D;}
else if (a == 'E'){return E;}
else if (a == 'F'){return F;}
else if (a == 'G'){return G;}
else if (a == 'H'){return H;}
else if (a == 'I'){return I;}
}
/*cin >> x, y;
if (y == 1)
{
cin >> move;
if (move == 'B'){tic[0] = 'O';}
}
else if (y == 2)
{
cin >> move;
t = convert(move);
tic[t] = 'X';
}*/
CORRECT ANSWER:
#include <iostream>
using namespace std;
char convert(char&);
int main ()
{
int ire = 9;
int moves;
char irel;
while (ire > 0)
{cin >> irel; ire--;}
char tic[9];
int nah = 8;
while (nah >= 0)
{
tic[nah] = '*';
nah--;
}
cin >> x;
cin >> y;
cin >> move;
if (y == 1)
{
if (move == 'A'){t = 0; tic[t] = 'O';}
else if (move == 'B'){t = 1; tic[t] = 'O';}
else if (move == 'C'){t = 2; tic[t] = 'O';}
else if (move == 'D'){t = 3; tic[t] = 'O';}
else if (move == 'E'){t = 4; tic[t] = 'O';}
else if (move == 'F'){t = 5; tic[t] = 'O';}
else if (move == 'G'){t = 6; tic[t] = 'O';}
else if (move == 'H'){t = 7; tic[t] = 'O';}
else if (move == 'I'){t = 8; tic[t] = 'O';}
else {cout << "Out of bounds"; return 0;}
}
else if (y == 2)
{
if (move == 'A'){t = 0; tic[t] = 'X';}
else if (move == 'B'){t = 1; tic[t] = 'X';}
else if (move == 'C'){t = 2; tic[t] = 'X';}
else if (move == 'D'){t = 3; tic[t] = 'X';}
else if (move == 'E'){t = 4; tic[t] = 'X';}
else if (move == 'F'){t = 5; tic[t] = 'X';}
else if (move == 'G'){t = 6; tic[t] = 'X';}
else if (move == 'H'){t = 7; tic[t] = 'X';}
else if (move == 'I'){t = 8; tic[t] = 'X';}
else {cout << "Out of bounds"; return 0;}
}
else {cout << "Invalid format"; return 0;}
moves--;
}
if (moves == 0){cout << tic[0] << tic[1] << tic[2] << endl << tic[3] <<
tic[4] << tic[5] << endl << tic[6] << tic[7] << tic[8] << endl << endl;
}
else {cout << "Invalid format"; return 0;}