Error message trying to pass array by reference...
I get some error messages when I try and pass it that way.
line: 13 declaration of `array' as array of references
In function `int main()':
line: 30 invalid conversion from `char (*)[3]' to `int'
line: 13 too many arguments to function `void initBoard(int)'
line: 30 at this point in file
line: 30 At global scope:
line: 91 declaration of `refArray' as array of references
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 initBoard (char &array[][COLS], int );
void displayBoard(char [][COLS], int);
void player1 (int rowX, int colX, char array[][COLS] );
void player2 (int rowO, int colO, char array[][COLS] );
char winner (char array[][COLS], char answer);
void playOneGame(char B[][COLS], char answer);
int main ()
{
char yes; //Variable to hold response for new game
char B[ROWS][COLS] = {{'*','*','*'},{'*','*','*'},{'*','*','*'}}; //Initiailizing tictactoe board
char answer = 'n' ; //Initializing winner
cout << "To play the game enter the row in which you would like to place your marker and press enter. Then do the same for the column.\n";
//Initializing playing board
do
{
initBoard(B, ROWS);
displayBoard(B, ROWS);
playOneGame(B, answer);
cout << "Another game? Y/N" ;
cin >> yes;
}
while (yes == 'Y' || yes == 'y') ;
system("pause");
return 0;
}
//************************************************************
//This function allows players to play 1 game of tic tac toe *
//************************************************************
void playOneGame (char B[][COLS], char answer)
{
int rowX = 0 ;
int colX = 0 ;
int rowO = 0 ;
int colO = 0 ;
for (int i = 0; i < 6 ; i++)
{
player1 (rowX, colX, B);
answer = winner(B, answer) ;
if (answer == 'x')
break;
displayBoard(B, ROWS);
player2 (rowO, colO, B);
answer = winner(B, answer);
if (answer == 'o')
break;
displayBoard(B, ROWS);
}
}
//**********************************
//This function displays the board *
//**********************************
void displayBoard ( char array[][COLS], int rows )
{
for (int x = 0; x < rows; x++)
{
for (int y = 0; y < COLS; y++)
{
cout << array[x][y] << " ";
}
cout << endl;
}
}
//***************************************
// This function initializes the board *
//***************************************
void initBoard ( char &refArray[][COLS], int rows )
{
char refArray[ROWS][COLS] = {{'*','*','*'},{'*','*','*'},{'*','*','*'}};
}
I only put up part of the program that involves the initBoard function and I have tried putting an & just about everywhere.