reading data into 2d array
I know that you can input multiple items at a time
cout<<"Enter length and width: ";
cin>>length>>width;
but is it possible to read data like that into an array?
I have this right now...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
//reads data into array
for (int i=0; i<rows; i++)
{
for(int j=0; j<columns; j++)
{
cout<<"Enter data: ";
cin>>table[i][j];
}
}
//prints array
for (int i=0; i<rows; i++)
{
for (int j=0; j<columns; j++)
{
cout<<table[i][j]<<" ";
}
cout<<endl;
}
|
and i want to be able to read in each row by just asking the user
cout<<"Enter row one: ";
cin>>table[][]>>table[][];
or however it is done correctly.
What you have looks correct to me
you could do this
1 2
|
cout<<"Enter row one: ";
cin>>table[i][0]>>table[i][1] << table[i][2] << table[i][3];
|
but this does the same thing that you currently have.
Topic archived. No new replies allowed.