My goal is dynamically allocate 2 dimensional array such that it prompts the user to input the size of the row and column of the matrix array they want to create. After dynamically allocating the size of the rows and columns, the user will input the values of whatever they wish. The following is my C++ code:
#include <iostream>
using namespace std;
int main()
{
int* x = NULL;
int* y = NULL;
int numbers, row, col;
cout << "Please input the size of your rows: " << endl;
std::cin >> row;
cout << "Please input the size of your columns: " << endl;
std::cin >> col;
x = new int[row];
y = new int[col];
cout << "Please input your array values: " << endl;
for (int i = 0; i<row; i++)
{
for (int j = 0; j<col; i++)
{
std::cin >> numbers;
x[i][j] = numbers;
}
}
cout << "The following is your matrix: " << endl;
for (int i = 0; i < row; i++)
{
for (int j = 0; j<col; j++)
{
std::cout << "[" << i << "][" <<j << "] = " << x[i][j] << std::endl;
}
}
delete[] x;
delete[] y;
system("pause");
return 0;
}
Unfortunately, when I run this code on Visual Studios, it is giving me compile errors.