How do I find the Averages for this program?

Hello, I am very new to programming and I am currently taking a c++ class. The task was to Write a program that asks the user for rainfall values for each month of a year, one month at a time. The program should then calculate the average monthly rainfall (or snowfall) for the whole year, and then, for each month, print out a line saying how much the rainfall for that month was above or below the average (negative numbers for lower values are fine).

I have written the code below but I have no idea how to even find the above or below averages. If someone can help me understand, I would greatly appreciate it!

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
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
 
string get_rain_value(string month) {
	cout << "Enter the rainfall value for " << month << ": ";
	string answer;
	cin >> answer;
	return answer;
}
 
int main() {
	vector<string> months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
	vector<string> rain_values;
	for (string month: months) {
		rain_values.push_back(get_rain_value(month));
	}
	cout << endl;
	for (int i = 0; i < months.size(); i += 1) {
		string start = rain_values[i];
		cout << "Rainfall value for " << months[i] << " was " << start << endl;
	}
}
Last edited on
Are the rainfall values really words? Was the rainfall for January "Unusually low" or 42?
Topic archived. No new replies allowed.