Hello.
I have a simple code in MS Visual Studio with C++ that aims to enter values into a two-dimensional matrix and display the entered values on the screen.
When I write exactly the same code in DevC++, it works but in MS Visual Studio, it gives the error "C2131 expression did not evaluate to a constant" on the line I marked as LINE 39.
I'm guessing it's an issue with the compiler or C++ standards but I couldn't find a solution for this code.
How can I solve this problem? How can I make the code I wrote work?
Thank you in advance to everyone who takes the time to help.
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int R, C;
cout << "Enter the value of the row: "; cin >> R;
cout << "Enter the value of the column: "; cin >> C;
cout << endl;
int a[R][C]; // >>>>>>>>>>>>>>>> LINE 39, C2131 Error <<<<<<<<<<<<<<<
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
cout << i + 1 << ". row, " << j + 1 << ". column: "; cin >> a[i][j];
}
cout << endl;
}
cout << endl << endl;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
cout << "\t" << a[i][j];
}
cout << endl;
}
return 0;
}