I'm pretty new to coding in c++ so I apologize if this question has a very apparent simple answer. I'm trying to create a matrix of random numbers from -1 to 1. These are the two functions I am using:
#include <iostream>
#include "matrix_fill_random.cpp"
using namespace std;
int main(int argc, int argv[]){
int n1, n2, n3;
if (argc != 4) {
cerr << "This program requires 3 argument!" <<endl;
return 1;
}
else{
n1 = argv[1];
n2 = argv[2];
n3 = argv[3];
double** a;
matrix_fill_random(n1, n2, a);
return 0;
}
}
and
#include <iostream>
using namespace std;
int matrix_fill_random(int n1, int n2, double** a){
for (int i=0; i<n1; i++){
for (int j=0; j<n2; j++){
double num = rand() % 2 - 1;
a[i][j]=num;
}
}
return 0;
}
Ultimately I'm trying to create two matrices and then multiply them together so n1, n2, and n3 represent the rows and columns of two matrices, but that isn't all too important right now. I think the error might be in how I declare my variables or pass them to other functions but I'm not entirely sure.
I feel like if I can understand the principle of creating one of the matrices then that would translate to the other functions I need to use.
matrix_fill_randomis assigning values toa[i][j]but you haven't allocated any memory fora.mainischar *argv[]notint argv[]. This will cause yourn1 = argv[1]to fail compilation (which it should since it's invalid). You need to convertargv[1]to int. Likewise for the other n's.#include "matrix_fill_random.cpp"should be.hor.hpp