/*
A game of Tic Tac Toe has just been completed. Write a function that prints whether X's or O's have won. The game board is passed in as an array of integers in row-column order. The Number 2 represents X and the number 1 represents O. A zero represents that the space is empty.
For example the gameboard below would be represented as int* gameboard = [2,0,1,1,1,0,2,2,2]
x-o
----
oo-
----
xxx
*/
#include <iostream>
void tic_tac_toe(int* gb)
{
for(int i = 0; i < 3; i++)
{
int product = 1;
for(int j = 0; j < 3; j++)
{
product *= gb[3 * i + j];
}
if(product == 1)
{
printf("O won.");
return;
}
else if(product = 8)
{
printf("P won.");
return;
}
}
int dia_product1 = gb[0] * gb[4] * gb[8];
if(dia_product1 == 1)
{
printf("O won.");
return;
}
else if(dia_product1 = 8)
{
printf("P won.");
return;
}
int dia_product2 = gb[2] * gb[4] * gb[6];
if(dia_product2 == 1)
{
printf("O won.");
return;
}
else if(dia_product1 = 8)
{
printf("P won.");
return;
}
printf("No won.");
return;
};
int main()
{
int gameboard[] = {2,0,1,1,1,0,2,2,2};
tic_tac_toe(gameboard);
return 0;
}