Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

trouble returning a 2d array from function

$
0
0
I am trying to return the coordinates input by the user to place a piece for a connect four game. however i keep getting this error.

main.cpp:132: error: cannot convert 'char (*)[6]' to 'int (*)[6]' for argument '1' to 'int userCoordinates(int (*)[6], int)'


the 2d array is data type char because i am using the space bar as a blank spot so i would assume the userCoordinate function would also have to be a char because i am going to assign the blank space to the letter R (first letter of name).

i thought at one point i could use nested foor loops but was not able to get that to work out.

also i have taken out error checking and a few other function calls in main that create the board etc because i didnt want to include a bunch of stuff that was not relevant to my current problem.

ROWS is a global variable of 7
COLUMNS is a global variable of 6
USER is a global variable of R
for a combined 7 x 6 gameboard


this is userCoordinate function

char userCoordinates(int board[][COLUMNS], int numRows)
{
    int row, col;
    
    cout << "where would you like to place your piece: ";
    cout << "Row choice is 0 - 6: ";
    cin >> row;
    
    cout << "Column choices are 0 - 5: ";
    cin >> col;

    board[row][col] = USER;
    
   //return board[row][col];
    
}





int main ()
{


    do 
    {
        
    // user choice 
    userCoordinates(GameBoard,ROWS);
    
    

    }while(contOrQuit != 'Q');

    return 0;
}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>