Hello guys, I'm trying to code a program where it asks the user to put a number represent the numbers in an array. The user then will enter the numbers in the array list.
I've made a few amendments. And the output is not like what I expect.
#include <iostream>
usingnamespace std;
void minmax(double *numbers, int npts, double *min_ptr, double *max_ptr);
int main()
{
int i, npts;
double min, max;
double arr[100];
cout << "How many numbers would you like to enter?" << endl;
cin >> npts;
cout << "Enter the " << npts << " numbers separated by whitespace." << endl;
for (i=0; i<npts; i++)
cin >> arr[i];
minmax(arr, npts, &min, &max);
cout << "The min is " << min << " and the max is " << max << endl;
return 0;
}
You appear to be trying to return a pointer to the function, but your function is prototyped with a void return type, which means you shouldn't be returning anything. Your function implementation and your function prototype don't match as they should. Since you can't change the prototype you will need to change the implementation.
You don't have to return anything from function void minmax(), first because the void return type prohibits it. Second, results are passed back to main via the pointer parameters min_ptr and max_ptr.
Also, the array defined in main() is passed via the first parameter, double *numbers. You should not be defining an additional array inside the function minmax (line 7).