1. ## two dimensional vector

I know this is probably simple but I cannot get my user entered information to show up in my table display. I have messed with this until I am blind. Can someone please help me. Also can I make calculations by column?
<code>
int x ;
int y;

for( int row = 0; row < table.size(); row++ )
{
cout << "Enter Salesman number.";
cin >> x ;

for( int col = 1; col < table[row].size(); col++ )
{
cout << "Enter number sold.";
cin >> y;
}
}

cout << "Display table\n";
for( row = x; row < table.size(); row++ )
{
for( int col = y; col < table[row].size(); col++ )
cout << table[row][col] << '\t';
cout << endl;
}
</code>

2. Show us your declarations- or all your code. What is table defined as?

3. Thanks for the response! Here is all of my code.

<code>

#include<iostream>
#include <vector>
#include<iomanip>

using namespace std;

using std::setw;
using std::setiosflags;
using std::setprecision;

int main()
{

const int ROWS = 2,
COLUMNS = 3;

//instantiate a double dimen vector
vector< vector<double> > table(ROWS,
vector<double>(COLUMNS, 0.0) ) ;

cout << "Value in row 0, column 2: " << table[0][2] << "\n";

cout << "Number of Rows: " << table.size() << "\n";

cout << "Number of Columns: " << table[1].size() << "\n";

int x ;
int y;

for( int row = 0; row < table.size(); row++ )
{

cout << "Enter Salesman number.";
cin >> x ;

for( int col = 1; col < table[row].size(); col++ )
{
cout << "Enter number sold.";
cin >> y;

}

}

cout << "Display table\n";
for( row = x; row < table.size(); row++ )
{
for( int col = y; col < table[row].size(); col++ )
cout << table[row][col] << '\t';
cout << endl;
}

return 0;

}

4. why do some people use the vector library? why cant you just use

Code:
```int array[10][10];
//a two dimensional array of int with 10 rows and 10 columns```

5. when you use cin >> x, and cin >> y, it writes the input value to x or y. your loop just keeps over writing the same variables instead of adding the values to your table.

6. I'm sorry I don't understand. Could you give me an example?
Thanks. Why does my table just print out zeros and not the last entry?

7. Why not use a matrix header file...

8. I have no idea where you plan on storing or how you plan on using the salesman number, but if you want to store the number of items sold in a table, then you need to make sure you add it to the vectors like so:

cin>>y;
table[rows].push_back(y);

Or better yet, unless you think you might change the number of rows and columns in the future, use a two-dimensional array which is easier.

9. Doesn't using push_back add another row or column? I just want to fill my rows and columns with user info.

10. The best way is: go buy a book.

Vectors are cool, but unless you're using them as a vector, by adding, removing, and modifying, they're pointless.

do this:

Code:
`double table[ROWS][COLUMNS];`
How is this set up?
rows=2
collumns=3

so....

Code:
```           row
0    1
0  x    x
col  1  x    x
2  x    x
3  x    x```
Remember, all arrays are zero-based. So a statement like this:

Code:
`for( int col = 1; col < table[row].size(); col++ )`
Also, why do this:

Code:
```cout << "Number of Rows: " << table.size() << "\n";
cout << "Number of Columns: " << table[1].size() << "\n";```
When you can replace table.size() with ROWS and the other with COLUMNS? Its more efficient.

Why does it print zeros? Because you filled it with zeros. Remember this?

Code:
```vector< vector<double> > table(ROWS,
vector<double>(COLUMNS, 0.0) ) ;```
That 0.0 is filling the whole collums with zeros. And no where in your code do you fill it up with somthing else.

BTW, I can't make sense of your program, it just doesn't make any sense on what you're doing. You're output routine is very wierd, printing everything bottom-right of the coordinates (x,y)the user entered...

11. Side note: Code tags are with [ and ], not < and >.

12. Oops, you are right, i missed that you initialized them already, I thought you hadn't. Anyways, to put data into the table, you need to do something like this:

cin>>table[row][col];

And like it has been stated before, vectors for something like this are pointless, use two-dimensional arrays.

13. Originally posted by nextus
why do some people use the vector library? why cant you just use

Code:
```int array[10][10];
//a two dimensional array of int with 10 rows and 10 columns```
See: http://www.parashift.com/c++-faq-lit....html#faq-34.1
Although I do agree that a vector of vectors is... ...stupid.

14. PJYelton - Thank-you very much! You actually helped me.