I am having trouble using pointers in this program. The program has to create a matrix with random numbers in a range of 1 and a 'max' number the user writes. This is my code:
#include<iostream>
#include<cmath>
#include <stdlib.h>
#include <ctime>
using namespace std;
int get_n();
float** create_matrix(int &n, float** m);
int main (int argc, char *argv[]) {
int n;
n=get_n();
float** m[n][n];
m=create_matrix(n, m);
return 0;
}
int get_n(){
int n;
do
{
cout<<"Write N between 3 and 10: ";
cin>>n;
} while (n<11&&n>2);
cout<<endl;
return n;
}
float** create_matrix(int &n, float** m){
int maxi;
srand(time(NULL));
cout<<"Insert max term: ";
cin>>maxi;
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
float aux=0;
aux=1+rand()%((1+maxi)-1);
m[i][j]=aux;
}
}
return m;
}
When I run it, I get this error:
ej2.cpp:19:21: error: cannot convert 'float** (*)[n]' to 'float**' for argument '2' to 'float** crear_matriz(int&, float**)'
I am not figuring out how to properly fix the code to avoid this problem?