fork download
  1. //Andrew Alspaugh CS1A Chapter 11. P.646. #4
  2. //
  3. /*****************************************************************************
  4. Store Weather Statistcs
  5. ____________________________________________________________________________
  6. This program does blah blah blah with weather statistics displays a bunch of
  7. random numbers
  8. ____________________________________________________________________________
  9. //Data Dictionary
  10. //Inputs
  11.  
  12.   const int months = 12;
  13.   Weather weather[months];
  14.  
  15. //Outputs
  16.  
  17.   float totalRain = 0.0;
  18.   float averageRain;
  19.   float totalAvgTemp = 0.0;
  20.  
  21.   float highestTemp = -1000.0; // initial value very low
  22.   int highMonth = 0;
  23.  
  24.   float lowestTemp = 1000.0; // initial value very high
  25.   int lowMonth = 0;
  26. *****************************************************************************/
  27.  
  28. #include <iostream>
  29. using namespace std;
  30.  
  31. struct Weather
  32. {
  33. float rainfall;
  34. float highTemp;
  35. float lowTemp;
  36. float aver;
  37. };
  38.  
  39. int main()
  40. {
  41. //Data Dictionary
  42. //Inputs
  43.  
  44. const int months = 12;
  45. Weather weather[months];
  46.  
  47. //Outputs
  48.  
  49. float totalRain = 0.0;
  50. float averageRain;
  51. float totalAvgTemp = 0.0;
  52.  
  53. float highestTemp = -1000.0; // initial value very low
  54. int highMonth = 0;
  55.  
  56. float lowestTemp = 1000.0; // initial value very high
  57. int lowMonth = 0;
  58.  
  59. //INPUT
  60. for(int i = 0; i < months; i++)
  61. {
  62. cout << "Enter Rainfall for Month " << i + 1 << " :" << endl;
  63. cin >> weather[i].rainfall;
  64.  
  65. cout << "Enter Highest Temperature for Month " << i + 1 << " :" << endl;
  66. cin >> weather[i].highTemp;
  67.  
  68. cout << "Enter Lowest Temperature for Month " << i + 1 << " :" << endl;
  69. cin >> weather[i].lowTemp;
  70.  
  71. weather[i].aver = (weather[i].highTemp + weather[i].lowTemp) / 2.0;
  72.  
  73. totalRain += weather[i].rainfall;
  74. totalAvgTemp += weather[i].aver;
  75.  
  76. if(weather[i].highTemp > highestTemp)
  77. {
  78. highestTemp = weather[i].highTemp;
  79. highMonth = i + 1;
  80. }
  81.  
  82. if(weather[i].lowTemp < lowestTemp)
  83. {
  84. lowestTemp = weather[i].lowTemp;
  85. lowMonth = i + 1;
  86. }
  87. }
  88.  
  89. //PROCESS
  90.  
  91. averageRain = totalRain / months;
  92.  
  93. float overallAvgTemp = totalAvgTemp / months;
  94.  
  95. //OUTPUT
  96.  
  97. cout << "Total Rainfall for the year: " << totalRain << endl;
  98.  
  99. cout << "Average Monthly Rainfall: " << averageRain << endl;
  100.  
  101. cout << "Highest Temperature of the year: " << highestTemp << " in month " << highMonth << endl;
  102.  
  103. cout << "Lowest Temperature of the year: " << lowestTemp << " in month " << lowMonth << endl;
  104.  
  105. cout << "Average of all monthly average temperatures: " << overallAvgTemp << endl;
  106.  
  107. return 0;
  108. }
Success #stdin #stdout 0.01s 5316KB
stdin
5678
80
40
60
435
235
23
42
342
4234
234
23
4
24
25
47
658
6
3
5
35
2
42
3423
5
347
84
6835
435
32
4
324
12
223
5
645
746
76
7
345
34
534
6
57
4687
658
6
7
546
3
54
35
245
2
634
6
457
457
56
87
5
54
524
52
34
23
423
4
436
356
5
62
432
4
23
5
3426
547
46
857
96
09
89
678
56
67
66
34
52
5
2
324
25
5678
80
40
60
435
235
23
42
342
4234
234
23
4
24
25
47
658
6
3
5
35
2
42
3423
5
347
84
6835
435
32
4
324
12
223
5
645
746
76
7
345
34
534
6
57
4687
658
6
7
546
3
54
35
245
2
634
6
457
457
56
87
5
54
524
52
34
23
423
4
436
356
5
62
432
4
23
5
3426
547
46
857
96
09
89
678
56
67
66
34
52
5
2
324
25
stdout
Enter Rainfall for Month 1 :
Enter Highest Temperature for Month 1 :
Enter Lowest Temperature for Month 1 :
Enter Rainfall for Month 2 :
Enter Highest Temperature for Month 2 :
Enter Lowest Temperature for Month 2 :
Enter Rainfall for Month 3 :
Enter Highest Temperature for Month 3 :
Enter Lowest Temperature for Month 3 :
Enter Rainfall for Month 4 :
Enter Highest Temperature for Month 4 :
Enter Lowest Temperature for Month 4 :
Enter Rainfall for Month 5 :
Enter Highest Temperature for Month 5 :
Enter Lowest Temperature for Month 5 :
Enter Rainfall for Month 6 :
Enter Highest Temperature for Month 6 :
Enter Lowest Temperature for Month 6 :
Enter Rainfall for Month 7 :
Enter Highest Temperature for Month 7 :
Enter Lowest Temperature for Month 7 :
Enter Rainfall for Month 8 :
Enter Highest Temperature for Month 8 :
Enter Lowest Temperature for Month 8 :
Enter Rainfall for Month 9 :
Enter Highest Temperature for Month 9 :
Enter Lowest Temperature for Month 9 :
Enter Rainfall for Month 10 :
Enter Highest Temperature for Month 10 :
Enter Lowest Temperature for Month 10 :
Enter Rainfall for Month 11 :
Enter Highest Temperature for Month 11 :
Enter Lowest Temperature for Month 11 :
Enter Rainfall for Month 12 :
Enter Highest Temperature for Month 12 :
Enter Lowest Temperature for Month 12 :
Total Rainfall for the year: 17118
Average Monthly Rainfall: 1426.5
Highest Temperature of the year: 658 in month 6
Lowest Temperature of the year: 6 in month 6
Average of all monthly average temperatures: 313.875