Ok so I have this code to have users input numbers into an array but would like to make it into a function. I am new to C++ and am unsure how to go about it. Can anyone give me some hints or tips? I would greatly appreciate it. The code is as follows:
main()
{
int m;
int n;
int i;
int j;
int A[100][100];
m = get_input ();
n = get_input2 ();
cout << endl << "Enter positive integers for the elements of matrix A:" << endl;
for (i = 0 ; i < m ; i++)
for (j = 0 ; j < n ; j++)
cin >> A[i][j];
return;
}
newthe memory for the array, not define it on the stack, then free it afterwards. Pass in the dimensions, return thenewed data, then calldelete[]on it when you're done. (Unless you want to also pass in the allocated array? In which case you can use local variables for that too.)