hi guys , i have a problem with my code which when i print my random numbers , at the end it prints garbage numbers of negative integers. the random numbers are fine but the last line is not. i know it could be the function call but when i use fillRandom(arr,range,min); it says range and min are identifer undefined. Right now im using fillRandom(arr) which includes the code problem. please help and thank. Also, if it is a simply fix, can you give me the straight answer.
void fillRandom(int * , int range = 100, int min = 0);
//prototype
int main()
{
int arr[7];
case 2:
cout << "Here is your input:" << endl;
fillRandom(arr,range,min);
display(num);
cout << endl;
cout << " Would you like to use bubble sort 1) or selection sort 2) " << endl;
cin >> choice;
break;
}
void fillRandom(int *arr, int range, int min)
{
for (int i = 0; i < 7; i++)
{
arr[i] = rand() % range + min;
cout << arr[i] <<endl;
}
}
void display(int num[])
{
for (int count = 0; count < NUMBERS; count++)
{
cout << num[count] << " ";
// prints out the array
}
cout << endl;
srry code was long, text me if need it
In void fillRandom(int *arr, int range, int min) try changing the * to a &, I believe you want to be passing it by reference. Your full code would be helpful to find the exact problem.
Please also use code tags. They are the <> symbol on the right of the text box. It makes code easier to read.