This is translated from Icelandic but I hope y'all understand it.
Make a dimensional array with 9 seats (3*3) and use a loop to put in the letters X and O so it looks like this
XOX
OXO
XOX
Then use a loop to print it on the screen.
i would probably make 2 loops to go through the array (x and y)
then take the sum of both the loop counters and mod it by 2 (to check if its even or odd)
if its equal to 0 (its even) then set the value to X else (its odd) set the value to O
int main(int argc, char** argv)
{
//decalre array
char array[3][3];
//initialize array
for(int y = 0; y < 3;y++)
for(int x = 0; x < 3; x++)
if((x+y)%2 == 0)
array[y][x] = 'X';
else
array[y][x] = 'O';
//prints array
for(int y = 0; y < 3; y++)
{
for(int x = 0; x < 3; x++)
printf("%c ",array[y][x]);
printf("\n");
}
return 0;
}
if you want you can also easily calculate the number of rows and columns in the array and then use that in the loops to make it possible to scale the array to any size you desire.
#include <iostream>
#include <stdio.h>
int main()
{
// initialize array
char array[5][10];
//calculate rows & columns
int rows = sizeof(array) / sizeof(array[0]);
int columns = sizeof(array[0]) / sizeof(char);
//initialize array
for(int y = 0; y < rows;y++)
for(int x = 0; x < columns; x++)
if((x+y)%2 == 0)
array[y][x] = 'X';
else
array[y][x] = 'O';
//prints array
for(int y = 0; y < rows; y++)
{
for(int x = 0; x < columns; x++)
printf("%c ",array[y][x]);
printf("\n");
}
printf("rows: %d \n",rows);
printf("columns: %d \n",columns);
return 0;
}
If that didn't work try repasting the code I gave you! :)
Also he's using C++ 98/03 so take the stuff from the parameters of main() away if you're using C++11 (If you're new to C++ I recommend using C++11 (and 14) instead :) should be no reason to use 98 anymore especially not come C++20!