You don't need an array. You need three variables:
1. Temporary to hold the latest input.
2. Smallest to remember the smallest value that has been seen so far.
3. Largest to remember the largest value that has been seen so far.
At start no values have been seen yet.
The smallest should thus be at least as large as any input can possibly be.
The largest should thus be at least as small as any input can possibly be.
See
http://www.cplusplus.com/reference/limits/numeric_limits/
For each input value:
* If the new value is smaller than smallest, update the smallest.
* If the new value is larger than largest, update the largest.
After input is over, show smallest and largest.
PS.
Your current code includes headers that you don't need. Guideline is to include only the necessary headers.
It is better not to make a habit of
using namespace std;
. The standard library is in a namespace to reduce name conflicts and that line undoes all that work.
1 2 3 4 5 6 7 8 9 10 11
|
#include <iostream>
int main() {
using std::cout;
using std::cin;
using std::endl;
// your code
return 0;
}
| |