fork download
  1. //Andrew Alspaugh CS1A Chapter 7. P. 444. #2
  2.  
  3. ////////////////////////////////////////////////////////////////////////////////
  4. //Process Rainfall Values
  5.  
  6. //This program displays the annual rainfall, average monthly rainfall, the month
  7. //the most rainfall, and the month with the least rainfall.
  8. //____________________________________________________________________________
  9. //INPUTS
  10.  
  11. // SIZE // array declerator
  12. // MONTH // array which holds values of rainfall per month
  13. //OUTPUTS
  14.  
  15. // RainAnnual // Rainfall Per YEar
  16. // AverageRain // Average Rainfall Per Month
  17.  
  18. // highest // highest amount of rainfall
  19. // highMonth // Month with the Most Rainfall
  20.  
  21. // lowest // lowest amount of rainfall
  22. // lowMonth // Month with Least Rainfall
  23. ///////////////////////////////////////////////////////////////////////////////
  24.  
  25. #include <iostream>
  26. using namespace std;
  27.  
  28. int main()
  29. {
  30. //DATA DICTIONARY/////////////////////////////////////////////////////////////
  31.  
  32. //INPUTS//
  33. const int SIZE = 12;
  34. double MONTH[SIZE];
  35.  
  36. //OUTPUTS//
  37. double RainAnnual = 0;
  38. double AverageRain = 0;
  39.  
  40. double highest;
  41. int highMonth;
  42.  
  43. double lowest;
  44. int lowMonth;
  45.  
  46. //INPUT////////////////////////////////////////////////////////////////////////
  47.  
  48. for (int count = 0; count < SIZE; count++) //input rainfall per month
  49. {
  50. cout << "Enter Rainfall Amount for Month " << (count + 1) << " : " ;
  51. cin >> MONTH[count];
  52.  
  53. while (MONTH[count] < 0) // Validate Inputs
  54. {
  55. cout << "INVALID: INPUT CANNOT BE NEGATIVE" << endl;
  56. cin >> MONTH[count];
  57. }
  58. cout << MONTH[count] << endl;
  59.  
  60. RainAnnual += MONTH[count]; //ACCUMULATOR FOR ANNUAL RAINFALL
  61. }
  62.  
  63. //PROCESS//////////////////////////////////////////////////////////////////////
  64.  
  65. //AVERAGE MONTHLY RAINFALL
  66. AverageRain = RainAnnual/(SIZE);
  67.  
  68. //MONTH WITH MOST RAIN
  69. highest = MONTH[0];
  70. for (int i = 1; i < SIZE; i++)
  71. {
  72. if (MONTH[i] > highest)
  73. {
  74. highest = MONTH[i];
  75. highMonth = i;
  76. }
  77. }
  78.  
  79. //MONTH WITH LOWEST RAIN
  80. lowest = MONTH[0];
  81. for (int i = 1; MONTH[i] > lowest; i++)
  82. {
  83. if (MONTH[i] > lowest)
  84. {
  85. lowest = MONTH[i];
  86. lowMonth = i;
  87. }
  88. }
  89.  
  90. //OUTPUT///////////////////////////////////////////////////////////////////////
  91. cout << endl;
  92.  
  93. cout << "Annual Rainfall This Year Was: " << RainAnnual << endl;
  94.  
  95. cout << "Average Rainfall Per Month Was: " << AverageRain << endl;
  96.  
  97. cout << "Month With Most Rain Was: Month " << highMonth << endl;
  98.  
  99. cout << "Month With Least Rain Was: Month " << lowMonth << endl;
  100.  
  101.  
  102. return 0;
  103. }
Success #stdin #stdout 0s 5320KB
stdin
123
987
456
1239
678
7654
1237
9832
7482
8127
6543
1234
stdout
Enter Rainfall Amount for Month 1 : 123
Enter Rainfall Amount for Month 2 : 987
Enter Rainfall Amount for Month 3 : 456
Enter Rainfall Amount for Month 4 : 1239
Enter Rainfall Amount for Month 5 : 678
Enter Rainfall Amount for Month 6 : 7654
Enter Rainfall Amount for Month 7 : 1237
Enter Rainfall Amount for Month 8 : 9832
Enter Rainfall Amount for Month 9 : 7482
Enter Rainfall Amount for Month 10 : 8127
Enter Rainfall Amount for Month 11 : 6543
Enter Rainfall Amount for Month 12 : 1234

Annual Rainfall This Year Was: 45592
Average Rainfall Per Month Was: 3799.33
Month With Most Rain Was: Month 7
Month With Least Rain Was: Month 1