Hi and thanks in advance for any help.
I am trying to learn how the <algorithm> functions work, and I am having a hard time with min and max_element. I would like to have an array with 10 numbers inputted by the user, and then output the lowest and highest numbers entered. Here is my code:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int Array[10], i;
for (i = 0; i < 10; i++) /*This is a loop, asking for input for each of the 10 array values.*/
{
cout << "Please enter a number for array" << i + 1 << ": ";
cin >> Array[i];
}
cout << "The smallest number is: " << min_element(Array, Array + 9) << endl;
cout << "The largest number is: " << max_element(Array, Array + 9) << endl;
system("Pause");
return 0;
}
Here is a test output:
Please enter a number for array1: 4
Please enter a number for array2: 5
Please enter a number for array3: 7
Please enter a number for array4: 3
Please enter a number for array5: 7
Please enter a number for array6: 9
Please enter a number for array7: 8
Please enter a number for array8: 5
Please enter a number for array9: 7
Please enter a number for array10: 4
The smallest number is: 0x22ff4c
The largest number is: 0x22ff54
Press any key to continue . . .
When the program completes and returns the min and max values, it returns 2 hex numbers. I am guessing this is because it is returning the actual memory value of Array rather than the value input by the user. However, I don't know how to fix this. Any help would be greatly appreciated. Thanks!
P.S. Please ignore the system("Pause"). I know not to use this. I just happen to be using a different IDE at the moment, and wanted an easy way to see the results without having to write a bunch of code since this is just practice.