How can I get my gen() function working? Generally I\'m just not familiar with p
ID: 3543140 • Letter: H
Question
How can I get my gen() function working? Generally I'm just not familiar with pointers.
//this is in main
int *arr;
while(true) {
cout << " Please enter a positive integer : ";
cin >> n ;
cout << endl ;
arr = gen(n);
cout << " Do you want to see the random numbers being generated? ";
cin >> resp;
if (resp[0] == 'y' || resp[0] == 'Y') {
if (arr )
print(arr,n) ;
else cout << "No score being genreated ";
}
//this is the function
int * gen(int n , int up= 100, int low = 0)
{
int number[200];
srand((unsigned) time(0)) ;
for(int i=0; i<n; i++)
{
return &number[i]= low + rand() % up ;
}
}
Explanation / Answer
int * gen(int n , int up= 100, int low = 0)
{
int number[200];
srand((unsigned) time(0)) ;
for(int i=0; i<n; i++)
{
number[i]= low + rand() % up ;
}
return number;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.