I keep getting an error message on line 23 using bloodshed dev-C++ that states:
"invalid conversion from '[*][3]' to 'int'"
I was wondering what the hell that meant.
here is my code:
Code:
#include <iostream>
#include <iomanip>
using namespace std;
//Global constants
const int COLS = 3; //Number of columns on the board
const int ROWS = 3; //Number of rows on the board
void displayBoard(int [][COLS], int);
void player1 (int, int, int);
void player2 (int);
int main ()
{
int space = 0 ;
int space2 = 0 ;
int B[ROWS][COLS] = {1, 2, 3, 4, 5, 6, 7, 8, 9 };
cout << "The playing board looks like:\n";
displayBoard(B, ROWS);
player1 (space, B, ROWS);
displayBoard(B, ROWS);
system("pause");
return 0;
}
void displayBoard ( int array[][COLS], int rows )
{
for (int x = 0; x < rows; x++)
{
for (int y = 0; y < COLS; y++)
{
cout << array[x][y] << " ";
}
cout << endl;
}
}
void player1 (int space, int array[][COLS], int rows)
{
cout << "Please select a space on the board to place your 'x' by selecting space 1 through 9\n";
cin >> space ;
if (space == 1) array[0][0] = 'x' ;
if (space == 2) array[0][1] = 'x' ;
if (space == 3) array[0][2] = 'x' ;
if (space == 4) array[1][0] = 'x' ;
if (space == 5) array[1][1] = 'x' ;
if (space == 6) array[1][2] = 'x' ;
if (space == 7) array[2][0] = 'x' ;
if (space == 8) array[2][1] = 'x' ;
if (space == 9) array[2][2] = 'x' ;
else cout << "invalid entry" ;
}
void player2 (int space2)
{
cout << "Please select a space on the board to place your 'x' by selecting space 1 through 9\n";
cin >> space2 ;
int B[ROWS][COLS] = {1, 2, 3, 4, 5, 6, 7, 8, 9 };
if (space2 == 1) B[0][0] = 'x' ;
if (space2 == 2) B[0][1] = 'x' ;
if (space2 == 3) B[0][2] = 'x' ;
if (space2 == 4) B[1][0] = 'x' ;
if (space2 == 5) B[1][1] = 'x' ;
if (space2 == 6) B[1][2] = 'x' ;
if (space2 == 7) B[2][0] = 'x' ;
if (space2 == 8) B[2][1] = 'x' ;
else if (space2 =9) B[2][2] = 'x' ;
}
char winner (char winner)
{
int B[ROWS][COLS] = {1, 2, 3, 4, 5, 6, 7, 8, 9 };
if (B[0][0] == B[0][1] && B[0][1] == B[0][2])
winner = B[0][0];
if (B[1][0] == B[1][1] && B[1][1] == B[1][2])
winner = B[1][0];
if (B[2][0] == B[2][1] && B[2][1] == B[2][2])
winner = B[2][0];
if (B[0][0] == B[1][0] && B[1][0] == B[2][0])
winner = B[1][0];
if (B[0][1] == B[1][1] && B[1][1] == B[2][1])
winner = B[1][1];
if (B[0][2] == B[1][2] && B[1][2] == B[2][2])
winner = B[2][2];
if (B[0][0] == B[1][1] && B[1][1] == B[2][2])
winner = B[2][2];
if (B[0][2] == B[1][1] && B[1][1] == B[2][0])
winner = B[1][1];
return winner ;
}