#include <iostream>
usingnamespace std;
constint N = 3;
int main()
{
int i, j;
double matrix[N][N+1];
int k = 1;
for (i = 0; i < N; i++)
{
cout << "Enter value for equation " << k << ": " << endl;
for (j = 0; j < N +1; j++)
{
cout << "[" << i << "]" << "[" << j << "] = ";
cin >> matrix[i][j];
}
k++;
}
cout << "Your equation is: " << endl;
for (i = 0; i < N; i++) {
for (j = 0; j < N+1; j++) {
cout << matrix[i][j] << " ";
}
cout << endl;
}
}
Can anyone help me how can I get any value of N from the keyboard but outside the main function? Because I still have some function outside of main using N
The size of an array has to be known to the compiler at compile time. Hence const int N = 3 is OK, but int N = 3 isn't as here N is a variable which can/could be changed at run-time so its value isn't known at compile time. If the size of an array is only obtained at run-time, then a variable sized container such as vector needs to be used.