0

Heres the code I have so far.

#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
    int row, column, done, i, c;
    string row_num;
    
    cout << "Please enter the numbers of rows and columns ";
    cin >> row;
    cin >> column;
    cout << "Please enter the numbers in the rows ";
    
    
    int user_array[row];
    
    for (c = 0; c < column; c++)
    {
    
     for (i = 0; i < row; i++)
     {    
        cin >> user_array[i]; 
     }   
    
    }
        
    cout << user_array[i][c];
    cin >> done;
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Murtan
0

Unless I'm mistaken, your code won't compile.

The first problem is that the compiler doesn't like you to declare the size of an array at runtime, it wasn't to know how big the array will be at compile time. (You can get around that by using an array that you allocate, but a 2 dimensional array is somewhat harder to allocate.)

On line 25 you accept input into the array as if it is single dimensional, but then on line 30 you attempt to output as if it had two dimensions. Line 30 appears to be outputting an indexed element, but there are no surrounding loops.

You will need to treat the array in the same fashion everywhere you use it.

It is also possible to 'emulate' a 2d array with a larger 1d array, but that might disagree with the spec (assignment) you are working on.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.