fork download
  1. //Roman Lara Delgado CSC5 Chapter 7, P.444, #1
  2. //
  3. /*******************************************************************************
  4. *
  5. * Determine The Largest and Smallest Value
  6. *_______________________________________________________________________________
  7. * This program determines the largest and the smallest value of a set of
  8. * numbers.
  9. * ______________________________________________________________________________
  10. * INPUT
  11. * value[SIZE] : entered values
  12. *
  13. * OUTPUT
  14. * highest : The highest value of a set of numbers
  15. * lowest : The lowest value of a set of numbers
  16. *******************************************************************************/
  17.  
  18. #include <iostream>
  19. using namespace std;
  20.  
  21. int main ()
  22. {
  23. /***************************************************************************
  24. * CONSTANTS
  25. * --------------------------------------------------------------------------
  26. * SIZE : number of elements in the array
  27. * *************************************************************************/
  28. //Initialize Program Constants
  29. const int SIZE = 10; //CONSTANT - number of elements in the array
  30.  
  31. //Declare Program Variables
  32. int value[SIZE]; //INPUT - entered values
  33. int highest; //OUTPUT - the highest value in the set of numbers
  34. int lowest; //OUTPUT - the lowest value in the set of numbers
  35.  
  36. //Input Array Values
  37. for (int count = 0; count < SIZE; count++)
  38. {
  39. cout << "Enter value #" << count + 1 << ": ";
  40. cin >> value[count];
  41. cout << endl;
  42. }
  43.  
  44. //Determine Highest Value
  45. highest = value[0];
  46.  
  47. for (int count = 1; count < SIZE; count++)
  48. {
  49. if (value[count] > highest)
  50. {
  51. highest = value[count];
  52. }
  53. }
  54.  
  55. //Determine Lowest Value
  56. lowest = value[0];
  57.  
  58. for (int count = 1; count < SIZE; count++)
  59. {
  60. if (value[count] < lowest)
  61. {
  62. lowest = value[count];
  63. }
  64. }
  65.  
  66. //Output Highest and Lowest Value
  67. cout << endl;
  68. cout << "The highest value of the set is: " << highest << endl;
  69. cout << "The lowest value of the set is: " << lowest << endl;
  70.  
  71. return 0;
  72. }
Success #stdin #stdout 0.01s 5300KB
stdin
389
35498
567
3978
479
108
4738
2039
54738
2398
stdout
Enter value #1: 
Enter value #2: 
Enter value #3: 
Enter value #4: 
Enter value #5: 
Enter value #6: 
Enter value #7: 
Enter value #8: 
Enter value #9: 
Enter value #10: 

The highest value of the set is: 54738
The lowest value of the set is: 108