help with showing text after void

hi guys , just wondering if y'all can give me a quick answer into correcting the function. when i call voidfillrandom in int main it doesnt continue the text of questioning the user of choice . please help and thank you in advance. P.S. I know its a small mistake but can you show the correct code to me .





int main()
{


case 2:
cout << "Here is your input:" << endl;
fillRandom(*arr,range,min);
cout << endl;
cout << " Would you like to use bubble sort 1) or selection sort 2) " << endl;
cin >> choice;

if (choice == 1)
{
sortArray(num, NUMBERS);

display(num);

}
else if (choice == 2)
{

selectionSort(arr,num);

display(num);
break;
}






system("pause");
return 0;
}

void fillRandom(int * arr, int range, int min)
{

for (int i = 0; i < 7; i++)
{
arr[i]= rand() % range + min;


}





}

sorry i didnt put the entire program in which it is long, but text me if you need it to solve the problem .
Last edited on
How is arr defined in main() when it is passed to fillRandom(...)? Why do you need to derefernce it?
Coder777 , do u mean that it doesn't have the number to print , such as print 7 numbers . If so I did add arr to be in int main in the top: int arr[7];
The code works to print out the function in void and shows it in the program. Can you still help please or anyone ?
I think Coder777 was getting at this line:

fillRandom(*arr,range,min);

If your main() is as follows (as we expect and as you stated above)

1
2
3
4
int main()
{
    int arr[7];
   ...


then calling fillRandom with *arr as the first argument is actually passing the contents of the first element of arr rather than a pointer to arr. Your fillRandom() function expects a pointer to an array, so it takes the value passed in, interprets it like a pointer, and starts populating random memory with random values.

Instead, remove the dereference operator (*) from your function call so you pass a pointer to the array to the function:

fillRandom(arr, range, min);
I feel stupid , thank you for clarifying it to me , I'm not that good with the names of vocabulary in c++ . I'll return to the conversation when I get home and try it out.
When I taken out the * symbol off my function call in int main it says the range and min are undeclared identifier . What should I do? I don't know if this helps which the prototype is void fillRandom (int *,int range =100 , int min = 0); please give me a straight answer to correct my code .
in int main it says the range and min are undeclared identifier. What should I do?

Declare them ... in main ... ie declare their types before use; presumably int here.
Since the prototype has default values for range and min you can omit them.
Topic archived. No new replies allowed.