Hello! I am a beginner and I'm trying to learn the mechanism behind creating a tic tac toe board. I created this function, and it's not outputting information correctly. I want to learn how to do this using a two-dimensional array and nested loops. Can someone explain what I am doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int board[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
//function to display board
void printBoard(){
int k = 0;
for(int i=0; i < 3; i++){
for(int j=0; j < 3; j++){
if ( i % 2 && j % 2 )
cout << board[i][j];
if ( i == 1 || i % 3 )
cout << '|';
if ( j == 1 || j % 3 )
cout << '_';
}
cout<<"\n";
}
}