You must do this assignment correctly as described below.
If you do not follow the directions or break the rules you will receive a 0 score.
Simulation of checking tic-tac-toe board for wins by counting X and O in rows, columns and diagonals.
in a loop for array sizes 3X3, 4X4, 5X5
Fill the array of characters with either X or O.
Print the array
Count number of X and O in each row, each column and each diagonal and print the totals.
Extra credit (10%) while printing counts print wins for X and/or O
You must correctly use the variables and functions as given below.
You must use the outer for loop that varies the size of the array.
That size must control the loops that fill, print and count.
All printing of counts must have labels for which row, column or diagonals the counts are for.
You must use loops, as demonstrated in class, to count the X and O in each direction.
Functions:
printArray(char array[5][5], int size) // row by row with label showing size
int row, col;
countRows(char array[5][5], int size) // prints a count of X and Os for each row extra prints wins
int row, col, xCount, oCount;
countColumns(char array[5][5], int size) // prints a count of X and O for each column, extra credit prints wins
int row, col, xCount, oCount;
countDiags(char array[5][5], int size) // prints a count of X and O for both diagonals, extra credit wins
int row, col, xCount, oCount;
// single loop (1) to count top left to bottom right
// print diagonal's counts with label
// single loop (1) to count other diagonal
// print other diagonal's counts with label
int main(intargc, char * argv[] ){
int row, col, size;
char array[5][5];
srand((unsigned)time(NULL)); // seedy stuff
for (size = 3; size <= 5; size++) {
// fill the array
for (row = 0; row < size; row++)
for (col = 0; col < size; col++)
array[row][col] = (rand() % 2) == 0 ? 'X' : 'O';
// print array: printArray(array, size)
// print each row's counts: countRows(array, size)
// print each column's counts: countColumns(array, size)
// print both diagonal's counts countDiags(array, size)
} // end outer array size loop
Hints:
Do it for one size array first. Do each part and test before moving on to the next. Get fill and print array working, then rows etc.
Remember size 5 is 0-4 indexes.
Don't forget to reset the xCount and oCount to 0 after each row or column part of the loops.
Once it works for size 3 do it for 3, 4, and 5 using the outer for loop.