fork download
  1. // Andres Guzman CSC5 Chapter 7, P. 444, #1
  2. /******************************************************************************
  3.  *
  4.  * DISPLAY SUBSCRIPT VALUES
  5.  * ____________________________________________________________________________
  6.  * Program will take inputs from programmer and the display the highest and
  7.  * lowest values from the subscript.
  8.  * ____________________________________________________________________________
  9.  *
  10.  * INPUT
  11.  *
  12.  * [SIZE] = Array Size
  13.  * array[SIZE] = Subscript to hold input values.
  14.  *
  15.  * OUTPUT
  16.  *
  17.  * highest = Largest input value
  18.  * lowest = Lowest input value
  19.  *
  20.  ******************************************************************************/
  21. #include <iostream>
  22. using namespace std;
  23. int main()
  24. {
  25. const int SIZE = 10; //Array Size
  26. int array[SIZE]; //Array Subscript
  27. int i; //Counter
  28. //Initilalizing For Loop to enter Value.
  29. for(i = 0; i < SIZE; i++)
  30. {
  31. cout << "Enter a Value: ";
  32. cin >> array[i]; //Allows input value and adds inputted Value into
  33. //subscript.
  34. cout << endl;
  35. }
  36. //Initializing Variables post input loop
  37. int highest = array[0]; //Assigns highest value to subscript 0
  38. int lowest = array[0]; //Assigns lowest value to subscript 0
  39. //Creating For Loop to find highest and lowest input value
  40. for(i = 0; i < SIZE; i++)
  41. {
  42. if(array[i] > highest) //Cycles through subscipt to find greater than 0
  43. highest = array[i]; //Assigns found subscript to highest variables
  44. if(array[i] < lowest) //Cycles through subscript to find lesser than 0
  45. lowest = array[i]; //Assigns found subscript to lowest variable
  46. }
  47. cout << "Largest Value: " << highest << endl;
  48. cout << "Smallest Value: " << lowest;
  49. return 0;
  50. }
Success #stdin #stdout 0s 5320KB
stdin
1 2 3 4 5 6 7 8 9 10
stdout
Enter a Value: 
Enter a Value: 
Enter a Value: 
Enter a Value: 
Enter a Value: 
Enter a Value: 
Enter a Value: 
Enter a Value: 
Enter a Value: 
Enter a Value: 
Largest Value: 10
Smallest Value: 1