help with two-dimensional arrays

Good evening everybody. Sorry if I have opened another discussion, but I couldn't find the soultion for my problem anywhere. Hoping someone can help me. It's just basic noob programming, but I just can't make out what's wrong with my code. Thanks in advance.
I want to print a matrix which can be chosen by the user (you can choose number of rows and columns, and the elements). The code in question is the following:

#include <iostream>
using namespace std;


int main (){
int row;
int column;
int matrix [row][column];
cout<<"choose number of rows and columns for the matrix: \n";
cin>>row;
cin>>column;

cout<<"these are the selected values for rows and columns: \n";
cout<<"number of rows: "<<row<<endl;
cout<<"number of columns: "<<column<<endl;

cout<<"now, select the elements: \n";
for (int i=0;i<row;i++){
for (int j=0;j<column;j++){
cout<<"insert element of row "<<i<<" and column "<<j<<": "<<endl;
cin>>matrix[i][j];
}
}
cout<<"the matrix will now be printed: \n";
for (int i=0;i<row;i++){
for (int j=0;j<column;j++){
cout<<matrix[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
The problem is that the elements printed in the matrix are just the last elements inserted. For example, if you choose a 2*2 matrix of elements 1 2 3 4, the result is:
3 4
3 4
and for a 3*3 matrix with elements 1 2 3 4 5 6 7 8 9,
7 8 9
7 8 9
7 8 9
how can I fix this and print the matrix like
1 2
3 4
or
1 2 3
4 5 6
7 8 9 ?
I tested your code and it worked fine
Topic archived. No new replies allowed.