//Devin Scheu CS1A Chapter 7, P. 444, #1
//
/**************************************************************
*
* FIND LARGEST AND SMALLEST ARRAY VALUES
* ____________________________________________________________
* This program finds the largest and smallest values in an
* array of 10 user-entered numbers.
* ____________________________________________________________
* INPUT
* arrayValues : The 10 values entered by the user
*
* OUTPUT
* largestValue : The largest value in the array
* smallestValue : The smallest value in the array
*
**************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
//Variable Declarations
const int ARRAY_SIZE = 10; //OUTPUT - Size of the array
int arrayValues[ARRAY_SIZE]; //INPUT - The 10 values entered by the user
int largestValue; //OUTPUT - The largest value in the array
int smallestValue; //OUTPUT - The smallest value in the array
//Prompt for Input
for (int i = 0; i < ARRAY_SIZE; i++) {
cout << "Enter value " << (i + 1) << ": ";
cin >> arrayValues[i];
cout << arrayValues[i] << endl;
}
//Find Largest and Smallest
smallestValue = arrayValues[0];
largestValue = arrayValues[0];
for (int i = 1; i < ARRAY_SIZE; i++) {
if (arrayValues[i] < smallestValue) {
smallestValue = arrayValues[i];
}
if (arrayValues[i] > largestValue) {
largestValue = arrayValues[i];
}
}
//Separator and Output Section
cout << "-------------------------------------------------------" << endl;
cout << "OUTPUT:" << endl;
//Output Result
cout << left << setw(25) << "Smallest Value:" << right << setw(15) << smallestValue << endl;
cout << left << setw(25) << "Largest Value:" << right << setw(15) << largestValue << endl;
} //end of main()