Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote