Try running your code in cpp.sh (click the gear on the right-hand side of your code, refresh the page if you don't see the gear icon) and see the errors + warnings that the compiler prints out.
http://cpp.sh/
If this is tic-tac-toe, that means you are trying to make a 3x3 board, which is
9 tiles. You have only made the size of your cell array to be 8.
int cell[8];
-->
int cell[9];
Arrays are 0-indexed, so cell[9]'s valid indices are [0], [1], ..., [8].
___________________________________
Also, as the (now deleted, but correct) post below me said, I'll paraphrase. x's ASCII value is 120. When you assign a char to an int, that number is casts to an int ('x' becomes 120). The design of your code is a bit odd because you are mixing ints (1-9) with chars ('x'/'o') in the same array.
With your current design, in your table() function, I would change it a bit by adding an if statement that says "if the character is an x or an o, print the character, otherwise print the 1-9 value"
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void table() {
int j=0;
for (int i = 0; i <= 8; i++) {
if (cell[i] == 'x' || cell[i] == 'o')
cout << (char)cell[i] << "|";
else
cout << cell[i] << "|";
j++;
if(j%3 == 0){
cout << endl <<"------" << endl;
}
}
}
|
Execution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
output on right
|
1|2|3|
------
4|5|6|
------
7|8|9|
------
your turn human
4
1|2|3|
------
x|5|6|
------
7|8|9|
------ |