Two Dimensional Array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SugaryLilly
    New Member
    • Apr 2008
    • 3

    Two Dimensional Array

    Hey, so for our c++ class, we are asked to ask the user to create a matrix.. they'll input the number of rows/columns. Then they'll input the values into each row and column.

    typedef vector<int> vd;
    typedef vector<vd> x;
    x Matrix;
    int rows, columns;
    int val1, val2;

    cout << "Please enter the number of rows in your matrix: " << endl;
    cin >> rows;
    Matrix.resize(r ows);

    I have this so far.. and I have an idea that I'm supposed to (or should) use for loops to get the input as to how man rows/columns they have. i'm just not entirely sure how to go about it.

    for(val1=0; val1<= rows; val1++)
    for(val2=0; val2<= columns; val2++)

    i'm think something like this, but i'm confused as to how to ask the user how many rows/columns they want and then how to put that in?
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    You've got the rows down already, as for columns, you can do something along the same lines, but obviously you can't just use resize() on the vector itself, you need to resize each component vector. How can you do this?

    Comment

    • hsn
      New Member
      • Sep 2007
      • 237

      #3
      research online in how to create a 2D array by using pointers.
      it will help you alot

      good luck

      hsn

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        You can also read this: http://bytes.com/forum/thread772412.html.

        Comment

        Working...