-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA4averagerainfall.cpp
52 lines (39 loc) · 1.18 KB
/
A4averagerainfall.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Calculates average rainfall
// By Emily Dayanghirang
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
string first_month,
second_month,
third_month;
double first_month_rainfall,
second_month_rainfall,
third_month_rainfall,
average_rainfall;
// Prompt user
cout << "Enter month: ";
cin >> first_month;
cout << "Enter rainfall for " << first_month << ": ";
cin >> first_month_rainfall;
cout << "Enter month: ";
cin >> second_month;
cout << "Enter rainfall for " << second_month << ": ";
cin >> second_month_rainfall;
cout << "Enter month: ";
cin >> third_month;
cout << "Enter rainfall for " << third_month << ": ";
cin >> third_month_rainfall;
// Calculate average rainfall
average_rainfall = (first_month_rainfall + second_month_rainfall + third_month_rainfall)/3.0;
// Display result
cout << "The average rainfall for "
<< first_month << ", "
<< second_month << ", and "
<< third_month << " is "
<< setprecision(2) << fixed
<< average_rainfall << " inches."
<< endl;
return 0;
}