I am developing a 2-Dimensional array in c++ using user input of rows and columns and want to allocate memory for the columns but I keep receiving an error which states;
A value of type "int" cannot be assigned to entity of type "int"
I know what the error means but how do I fix it it is annoying. Below is a portion of my code. Also I did not include the print section as I want to be able to transpose the array later.
// Local variables
int rows, columns;
// Prompting the user to enter the number of rows and columns
std::cout << "please input how many rows and columns you want accordingly: " << std::endl;
std::cin >> rows >> columns;
// Creating an array on the Heap memory and sizing it by the number of rows
int* arr = new int[rows];
// Assigning the values of rows
for (int i = 0; i < rows; i++) {
// Creating a new heap for columns into arr[i]
arr[i] = new int[columns];
}
// Getting the values of rows
for (int i = 0; i < rows; i++) {
// Assigning and Getting the values of columns
for (int j = 0; j < columns; j++) {
// Enter the elements of the array
std::cout << "Please enter a number: " << std::endl;
std::cin >> arr[i][&j];
}
}