So, basically what I'm trying to do is a Tic Tac Toe game for a project. I started with making 3 1-D Char Arrays to represent the game's bord. the code below compares the Arrays data to try and figure out if any of the winning possibilites were achieved by option x or y. There is a variable set to 0, this variable will change to 1 if player1 won and will change to 2 if player2 won, if it remains 0 then it's a draw. Now, there's 16 errors of Error C2446 '==': no conversion from 'const char [2]' to 'int'.
#include <stdio.h>
#include <conio.h>
#include <string.h>
//This function is made to check the result of the round, either one of the players win or it's a draw. It also states who is the winner or if it's a draw.
int main()
{
int playerwon = 0;//This variable is to indicate which player won, if it's = 1 then Player1 won, if 2 then player2 won, if it remains 0 then draw.
char board1[4] = {'-','-','-','\0'};
char board2[4] = { '-','-','-','\0'};
char board3[4] = { '-','-','-','\0'};
//Coloumns win check for X, Player 1.
if (board1[0] == board2[0] && board3[0] == board2[0] && board3[0] == 'x')
{
playerwon = 1;
}
else if (board1[1] == board2[1] && board3[1] == board2[1] && board3[1] == 'x')
{
playerwon = 1;
}
else if (board1[2] == board2[2] && board3[2] == board2[2] && board3[2] == 'x')
{
playerwon = 1;
}
//Rows win check for X, Player 1.
else if (board1[0] == board1[1] && board1[1] == board1[2] && board1[2] == 'x')
{
playerwon = 1;
}
else if (board2[0] == board2[1] && board2[1] == board2[2] && board2[2] == 'x')
{
playerwon = 1;
}
else if (board3[0] == board3[1] && board3[1] == board3[2] && board3[2] == 'x')
{
playerwon = 1;
}
//Diagonals win check for X, Player 1.
else if (board1[0] == board2[1] && board2[1] == board3[2] && board3[2] == 'x')
{
playerwon=1;
}
else if (board1[2] == board2[1] && board2[1] == board3[0] && board3[0] == 'x')
{
playerwon = 1;
}
//Coloumns win check for Y, Player 2.
else if (board1[0] == board2[0] && board3[0] == board2[0] && board3[0] == 'y')
{
playerwon = 2;
}
else if (board1[1] == board2[1] && board3[1] == board2[1] && board3[1] == 'y')
{
playerwon = 2;
}
else if (board1[2] == board2[2] && board3[2] == board2[2] && board3[2] == 'y')
{
playerwon = 2;
}
//Rows win check for Y, Player 2.
else if (board1[0] == board1[1] && board1[1] == board1[2] && board1[2] == 'y')
{
playerwon = 2;
}
else if (board2[0] == board2[1] && board2[1] == board2[2] && board2[2] == 'y')
{
playerwon = 2;
}
else if (board3[0] == board3[1] && board3[1] == board3[2] && board3[2] == 'y')
{
playerwon = 2;
}
//Diagonals win check for Y, Player 2.
else if (board1[0] == board2[1] && board2[1] == board3[2] && board3[2] == 'y')
{
playerwon = 2;
}
else if (board1[2] == board2[1] && board2[1] == board3[0] && board3[0] == 'y')
{
playerwon = 2;
}
//Printing the result of the round!
if (playerwon = 1) {
printf("Player one won this round!");
}
else if (playerwon = 2) {
printf("Player two won this round!");
}
else if (playerwon = 0) {
printf("This round is a draw!");
}
else {
printf("Error calculating the round result!");
}
return 0;
}