I need help in using 2d arrays in c++. I want to output a table that looks like this
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29 30
except i want to do it using a 2d array and have the user input a value (n) and the table to be nxn.
I literally have no idea where to start on this so any amount of help or suggestions would be greatly appreciated.

#include <iostream>
using namespace std;

int main()
{
int n, i, j;
cin >> n;
int board[n][n], array[n][n];

for(i=0;i<n; i++)
{
for(j=0;j<n;j++)
{
array[n][n]>>board[i][j];
}
}

for(i=0;i<n;i++){
cout<<endl;
for(j=0;j<n;j++){
cout<<" "<<board[i][j];
}
}

system("PAUSE");
return 0;
}

this is my code thus far, pretty much all it does right is output the correct number of columns and rows but not the correct values

This:

int n, i, j;
cin >> n;
int board[n][n], array[n][n];

is a good idea in theory, but the problem is that it won't work. If you're using a static array, the dimensions of that array need to be const when you declare it.
So in your case, you could go for one of these two options:
1. Use new and delete to make a dynamic array
2. Use nested vectors

See this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.