Hello, I'm trying to create a dynamic array of random numbers from 1 to c. I input b&c into main, but cut this down to make it easier to read. I'm trying to use a pointer, but can't get it syntax error free.
cpp:
1 2 3 4 5 6 7 8 9 10
int Class::array(int a[], int b, int c)
{
int* a = newint [ b ];
for(int i=0;i<b;i++)
{
srand(time(0));
a[i]= 1+rand() % c;
}
cout<< a;
}
Thanks that does work, but I need it in the format:
array1(int a[], int b, int c)
However, I think I'm supposed to be calling array0(int c) which is a random number into this function.
I will then need to call that function again to do a bunch of things to it.
Yeah, I might be missing something but I can't see the point of creating the array inside the class if you've already done it in main. But there ya go.
This might be of use.
http://www.tutorialspoint.com/cplusplus/cpp_passing_arrays_to_functions.htm