### Lowest value not printing

Hello, I'm working on this assignment and the instructions are to ask the user to enter 10 numbers and store it in an array. Then we're supposed to print the numbers entered followed by the lowest and highest integer they entered. My problem is printing the lowest number but it prints the highest. What am I missing?
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970`` `````` #include using namespace std; const int gSIZE = 10; void userInput(int myArray[gSIZE]); void findLowestValue(int myArray[gSIZE]); void findLargestValue(int myArray[gSIZE]); int main() { int myArray[gSIZE]; userInput(myArray); findLowestValue(myArray); findLargestValue(myArray); return 0; } void userInput(int myArray[gSIZE]) { int index = 0; cout << "Enter 10 numbers:" << endl; for(int row = 0; row < gSIZE; ++row) { cout << ++index << ". Enter a number: "; cin >> myArray[row]; } cout << endl; } void findLowestValue(int myArray[gSIZE]) { cout << "Of the values you entered: "; for(int row = 1;row < gSIZE; ++row) { cout << myArray[row] << ", "; if( myArray[10] > myArray[row]) myArray[10] = myArray[row]; } cout << endl; cout << "The lowest value you entered was: " << myArray[10] << endl; } void findLargestValue(int myArray[gSIZE]) { for(int row = 1;row < gSIZE; ++row) { if( myArray[10] < myArray[row]) myArray[10] = myArray[row]; } cout << "The largest value you entered was: " << myArray[10] << endl; }``````
Last edited on
myArray[10] is not a valid index when using the array.
You need to keep a variable for "lowest value so far" and compare/assign to that.
Hello av16352,

I do not know if you can use this or not. From the "<algorithm>" header file you have "std::sort" where after all the numbers are input you could sort the array then element (0)zero would contain the lowest number and element 9 would contain the highest.

If you can not use "std::sort" you could always write your own sort routine.

If you are not familiar with this yer C++ like other languages are (0)zero based, so you array elements start at (0)zero and got to 9 for 10 elements in the array.

Andy
The easiest way to find the lowest and the highest number is as the numbers are being entered:

 ``1234567891011121314151617181920212223242526272829`` ``````#include #include const size_t gSIZE {10}; int main() { int myArray[gSIZE] {}; int mymin {std::numeric_limits::max()}, mymax {std::numeric_limits::min()}; std::cout << "Enter " << gSIZE << " numbers: "; for (size_t row = 0; row < gSIZE; ++row) { std::cin >> myArray[row]; if (myArray[row] > mymax) mymax = myArray[row]; if (myArray[row] < mymin) mymin = myArray[row]; } for (size_t row = 0; row < gSIZE; ++row) std::cout << myArray[row] << ' '; std::cout << "\nLowest is " << mymin; std::cout << "\nHighest is " << mymax << '\n'; }``````