I'm trying to write code for the game tictactoe, i'm almost finished, I haven't yet written the part of the code that ends the game. My only problem is that c++ stops running, "Process terminated with status 0". Other than that the code runs fine. In fact it works perfectly until it gets terminated, can anyone help me? Indentation messed up the graphical part of the board function so don't mind that. The function board() creates a 3 by 3 grid labelled 1-9, the function game() replaces each number with an O or X depending on which number the plpayer picks, all done by the switch and while statmements. Here is my code, thank you.
using namespace std;
string a = "1";
string b = "2";
string c = "3";
string d = "4";
string e = "5";
string f = "6";
string g = "7";
string h = "8";
string i = "9";
string s1;
string s2;
string o = "O";
string x = "X";
string k = "Tic-Tac-Toe\n";
void ClearScreen() {
cout << string(100, '\n');
}
void board() {
std::cout << " " << k;
std::cout << " | | \n";
std::cout << " " << a << " | " << b << " | " << c << " \
n ";
std::cout << "___________|___________|___________\n";
std::cout << " | | \n";
std::cout << " " << d << " | " << e << " | " << f << " \
n ";
std::cout << "___________|___________|___________\n";
std::cout << " | | \n";
std::cout << " " << g << " | " << h << " | " << i << " \
n ";
std::cout << " | | \n";
std::cout << " Player 1:O, Player 2:X\n";
}
void game() {
board();
int z = 1;
while (z <= 9 && z % 2 == 1) {
std::cin >> s1;
int n1 = stoi(s1);
switch (n1) {
case 1:
a = o;
z++;
break;
case 2:
b = o;
z++;
break;
case 3:
c = o;
z++;
break;
case 4:
d = o;
z++;
break;
case 5:
e = o;
z++;
break;
case 6:
f = o;
z++;
break;
case 7:
g = o;
z++;
break;
case 8:
h = o;
z++;
break;
case 9:
i = o;
z++;
break;
}
board();
}
while (z <= 9 && z % 2 == 0) {
std::cin >> s2;
int n2 = stoi(s2);
switch (n2) {
case 1:
a = x;
z++;
break;
case 2:
b = x;
z++;
break;
case 3:
c = x;
z++;
break;
case 4:
d = x;
z++;
break;
case 5:
e = x;
z++;
break;
case 6:
f = x;
z++;
break;
case 7:
g = x;
z++;
break;
case 8:
h = x;
z++;
break;
case 9:
i = x;
z++;
break;
}
board();
}
}
int main() {
game();
}