fork download
  1. //Andrew Alspaugh CS1A Chapter 7. P. 444. #1.
  2.  
  3. //Determine Extreme Values
  4.  
  5. //This program determines the highest and lowest value of an array and displays
  6. //them.
  7.  
  8. //INPUT
  9. // values = 10 size of array
  10. // array array
  11. // count for loop first counter
  12. // i for loop highest/lowest counter
  13.  
  14. //OUTPUT
  15. // highest highest value
  16. // lowest lowest value
  17.  
  18. #include <iostream>
  19. using namespace std;
  20.  
  21. int main()
  22. {
  23. //DATA DICTIONARY
  24. //INPUTS
  25. const int values = 10;
  26. int array [values];
  27. int count;
  28. int i;
  29.  
  30. //OUTPUTS
  31. int highest;
  32. int lowest;
  33.  
  34. //INPUT (input values of array)
  35. for (count = 0; count < values; count++)
  36. {
  37. cout << "Enter value " << (count + 1) << " :" << endl;
  38. cin >> array[count];
  39.  
  40. }
  41.  
  42. //PROCESS
  43. //(determine highest)
  44. highest = array[0];
  45. for (i = 1; i < values; i++)
  46. {
  47. if (array[i] > highest)
  48. highest = array[i];
  49. }
  50.  
  51. //(determine lowest)
  52. lowest = array[0];
  53. for (i = 1; i < values; i++)
  54. {
  55. if ( array[i] < lowest)
  56. lowest = array[i];
  57. }
  58.  
  59. //OUTPUT
  60. cout << "Highest value is: "<< highest << endl;
  61. cout << "Lowest value is: " << lowest << endl;
  62. return 0;
  63. }
Success #stdin #stdout 0s 5316KB
stdin
2432
9432
8101
372
9102
46281
123
456
765
9876
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 :
Highest value is: 46281
Lowest value is: 123