hi, i am still beginner and don't know how to use but c++ and i was wondering how can i make array that its order is entered by the user but i don't know how to make int x[r][c] work ?
# include <iostream>
usingnamespace std;
int main()
{
int r=1, c=1;
cout << "please enter the number of rows" << endl;
cin >> r;
cout << "please enter the number of the colums" << endl;
cin >> c;
if (r > 0 && c > 0)
{
int x[r][c];
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
cout << "please enter the value of the order (" << i << "," << j << ")" << endl;
cin >> x[i][j];
}
}
}
else
cout << "please enter number of row and colums bigger then 0" << endl;
system("pause");
}
cout << "please enter the number of rows" << endl;
cin >> r;
cout << "please enter the number of the colums" << endl;
cin >> c;
int x[r][c];
This can not be done in c++. The array has to have a const value as your error is saying. If you want to do what you're code is showing. You'd have to allocate memory for the array.
@hellwolf @TarikNeaj don't understand what you guys are talking about. seems and runs fine in codeblocks and cpp.sh. adding cout shows inputs are indeed stored. here is the link:
cout << "please enter the number of rows" << endl;
cin >> r;
cout << "please enter the number of the colums" << endl;
cin >> c;
int x[r][c];
You cant do that in c++.If your compiler is not picking up on that then well, maybe get another one. You can go ask anyone who knows anything about programming.