I am trying to write an OLS regression in C++. I want the user to specify how many observations and variables goes into the X (independent variable matrix). I want to write this as a function outside the int main()
function. But everytime I return the array, I get a type error. How do I specify that I want function input_x
to return a matrix/array?
/******************************************************************************
Online C++ Compiler.
*******************************************************************************/
#include <iostream>
using namespace std;
int input_x(int num_rows, int num_cols){
int mat[num_rows][num_cols];
int user_input;
for (int i=0; i<num_rows; i++){
for (int j=0; j<num_cols; j++){
cout<<"Enter the value X:";
cin>>user_input;
mat[i][j]=user_input;
}
}
return mat;
}
int main()
{
int mat[1000][1000];
int input;
int rows;
int cols;
cout<<"How many row?";
cin>> rows;
cout<<"How many columns?";
cin>> cols;
//Enter the X data
input_x(rows,cols);
return 0;
}