int displayTable(int x, int y)
{
int mTable[x][y];
cout << "\n\n___________________________________________\n";
for (int i = 0; i < y; i++)
{
for (int i2 = 0; i < x; i++)
{
cout << "|";
mTable[i2][i] = i2 + i;
}
cout << "|\n";
cout << "------------------------------------------------------\n";
}
return mTable;
}
I am getting a error saying that x and y in the int mTable[x][y]; have to be const. Not sure how to get around this because I don't know what the size of the array is going to be until the user gives me x and y.
Guessing this has something to do with the address of the array but not sure how to go about fixing it atm. Here is all the code I have so far, if that helps.
I tried putting in the code you added above but I throws up errors (I even tried changing mtable to mTable in the second statement).
Is there a easier way to go about setting up this array based on user input? Trying to find a way that I can understand at my level and build on from there.
Oh good heavens, just use a 2d vector...
Really I see absolutely no reason to use an array in your case...
You would want to change the return value of your function to an integer pointer if you really want to use arrays. If you want to dynamically alloc in c++ you have to first make an array of pointers of size x or y then call new on each of those pointers of the other size... Not very simple and very c-like.
1 2 3 4 5 6
int **parray;
int x,y;
paray = newint* [x];
for(int i=0; i<x; i++)
paray[i] = newint [y];
however you can't forget to delete each individual pointer...