#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
usingnamespace std;
constint COLS = 20, rows = 20;
int board[rows][COLS];
void fillBoard(int board[rows][COLS]);
void showBoard(int board[rows][COLS]);
void findPeaks(int board[rows][COLS]);
int main()
{
fillBoard(board[rows][COLS]);
showBoard(board[rows][COLS]);
findPeaks(board[rows][COLS]);
return 0;
}
void fillBoard(int board[rows][COLS])
{
srand(time(NULL));
for(int i = 0; i < COLS; i++) {
for (int k = 0; k < rows; k++){
board[k][i] = (rand() % 50 + 1);
}
}
}
void showBoard(board[rows][COLS])
{
for(int m = 0; m <COLS; m++){
for(int n = 0; n < rows; n++)
cout << board[n][m] << " ";
}
}
void findPeaks(board[rows][COLS])
{
}
When I call my functions, the build log keeps telling me "error: invalid conversion from 'int' to 'int (*)(20)' [-fmpermissive]" and I don't know how to solve this problem. Any help would be appreciated. Thanks.
its not int to int, its int to int* * means "pointer". Pointers and arrays are quasi interchangeable. So somewhere you have something akin to this:
int a[10];
int x;
x = a; //cannot convert int* to int
so in main
fillBoard(board[rows][COLS]); //this is an integer. board[rows][cols] is a specific location in your 2d array, its the location at rows, cols. Its also out of range, but that is because you did not understand.
try fillBoard(board); //board is a 2d array, the function takes a 2d array, so it matches. board[x] is a 1d array. board[x][y] is an integer.
you may need to add at least a ; to findPeaks just to make it compile depending on your compiler and settings.
you left off 'int' on the later functions parameters, which won't compile and will likely give an even more cryptic error message.
int a[10];
int x;
x = a; //cannot convert int* to int
The only thing I could guess it would be would be the inclusion of rows and COLS in the array size but I can't do any work on the array if I don't pass the size to it as well. I tried removing the rows and COLS from both the prototype's and calling and it still says the same thing. The problem was with rows. Thanks for your help.
it compiled and ran for me after I fixed everything in my edited post above.
but what is it?
did you get the missing ints?
watch the messages too. it takes a while to understand c++ compiler messages; many of them are relics from the 80s and somewhat odd. Once you get it, its a huge benefit to see what its saying and fix it immediately instead of pondering what the heck it is going on about. Its one of the big ah-ha moments of c++. It almost pays to screw up code just to see what it will say about it for a while.