Why my tic tac toe program not working

#include <iostream>
#include <cstdlib>
#include <stdalign.h>
#include <string>
#define orif ||
using namespace std;
int main()
{

int z, turn, x;
bool win;

string square[9] = ("B ", "B ", "B ", "B ", "B ", "B ", "B ", "B ", "B ");
string O, X = ("O ", "X ");
do {
turn++;
if (turn%2 == 0) {


cin >> x;
square[x] = X;



}
else {



cin >> x;
square[x] = O;
}

cout << square [1] << square [2] << square [3] << endl << square [4] << square [5] << square [6] << endl << square[7] << square[8] << square[9];


}while(true);
}


this tic tac toe doesnt have a winning and draw option,
the extra things like bool win; and #define are going to be useful in the future but not now,

i want it to work like this

Input: 4
cout :
b b b
x b b
b b b
(loop)
Input : 3
cout :
b b o
x b b
b b b
and it will last like thos forever




but instead this happens:
Input : 5
cout:
b b
b b b
b b
(loop)
cout << "";



and get a black screen forver

why?

Last edited on
I discovered that the problem is in the arrays (string square[9])
how to fix it
in c/c++ element of array starts at 0. So if you said you array is of size 9 , you have access to element 0,1,2,3,4,5,6,7,8 (total of 9 right?) it crash because of this . Simply remove square[9] and start elements at 0.
Topic archived. No new replies allowed.