fork download
  1. // Kurt Feiereisel CSC5 Chapter 7, p.444, #1
  2. /*******************************************************************************
  3.  *
  4.  * Determine Highest and Lowest Values
  5.  * _____________________________________________________________________________
  6.  * This program accepts ten integers as input. The program will then determine
  7.  * and report which integer has the highest value and which integer has the
  8.  * lowest value
  9.  * _____________________________________________________________________________
  10.  * INPUT:
  11.  * array[] : Stores the ten integers inputted
  12.  *
  13.  * OUTPUT:
  14.  * highest : Integer with the highest value
  15.  * lowest : Integer with the lowest value
  16.  *
  17.  * ****************************************************************************/
  18. #include <iostream>
  19. using namespace std;
  20. int main()
  21. {
  22. // Initialize Constant
  23. const int SIZE = 10; // Constant: Number of integers for array to
  24. // hold
  25.  
  26. // Decalre Array
  27. int array[SIZE]; // Array to hold the 10 integers
  28.  
  29. // Input integers
  30. cout << "Please enter 10 integers." << endl;
  31. for(int index = 0; index < SIZE; index++)
  32. cin >> array[index];
  33.  
  34. // Initalize Variables
  35. int highest; // OUTPUT: highest integer inputted
  36. int lowest; // OUTPUT: lowest integer inputted
  37.  
  38. // Determine highest value
  39. highest = array[0];
  40. for (int count = 0; count < SIZE; count++)
  41. {
  42. if (array[count] > highest)
  43. highest = array[count];
  44. }
  45.  
  46. // Determine lowest value
  47. lowest = array[0];
  48. for (int count = 0; count < SIZE; count++)
  49. {
  50. if(array[count] < lowest)
  51. lowest = array[count];
  52. }
  53.  
  54. // Display Highest and Lowest Values
  55. cout << highest << " is the highest value." << endl;
  56. cout << lowest << " is the lowest value." << endl;
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0s 5304KB
stdin
34
565
23
65
86
21
46
27
75
23

stdout
Please enter 10 integers.
565 is the highest value.
21 is the lowest value.