E
erictham
#include <iostream>
#include <cmath>
using namespace std;
// implements a pseudo RNG generator by the linear congruential
generator
const int n1=100;
double *LRNG(int, int, int);
int main()
{
double *random;
int a,c,n ;
cout << "Please enter the seed for a and the constant for c";
cin >> a >> c;
cout << "How many random numbers do you want to generate?";
cin >> n;
random = LRNG(a, c, n);
for (int i=1; i<n1;i++)
{
cout << random << endl;
}
// How do u return a array from a function?
return 0;
}
double *LRNG(int a, int c, int seed, int n) {
double M;
//const int n1= 100;
double m0[n1], r[n1];
m0[1]= 1;
// How do u assign a variable size to an array??
M = pow(2,32);
for (int i=1;i<n1;i++)
{
r = fmod(a * m0+c,M);
}
return r;
}
Compile with error: warning C4172: returning address of local variable
or temporary
But on linking:
Linking...
LinearRNG.obj : error LNK2001: unresolved external symbol "double *
__cdecl LRNG(int,int,int)" (?LRNG@@YAPANHHH@Z)
Debug/LinearRNG.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
LinearRNG.exe - 2 error(s), 0 warning(s)
I am lost as to what to do next. thanks..
#include <cmath>
using namespace std;
// implements a pseudo RNG generator by the linear congruential
generator
const int n1=100;
double *LRNG(int, int, int);
int main()
{
double *random;
int a,c,n ;
cout << "Please enter the seed for a and the constant for c";
cin >> a >> c;
cout << "How many random numbers do you want to generate?";
cin >> n;
random = LRNG(a, c, n);
for (int i=1; i<n1;i++)
{
cout << random << endl;
}
// How do u return a array from a function?
return 0;
}
double *LRNG(int a, int c, int seed, int n) {
double M;
//const int n1= 100;
double m0[n1], r[n1];
m0[1]= 1;
// How do u assign a variable size to an array??
M = pow(2,32);
for (int i=1;i<n1;i++)
{
r = fmod(a * m0+c,M);
}
return r;
}
Compile with error: warning C4172: returning address of local variable
or temporary
But on linking:
Linking...
LinearRNG.obj : error LNK2001: unresolved external symbol "double *
__cdecl LRNG(int,int,int)" (?LRNG@@YAPANHHH@Z)
Debug/LinearRNG.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
LinearRNG.exe - 2 error(s), 0 warning(s)
I am lost as to what to do next. thanks..