HELP with program!!!

Can someone write up this code for me im self teaching myself just need a run through how it looks.


A program that calculates the average monthly rainfall for three months. The program should ask the user to enter the name of each month, such as June or July, and the amount of rain (in inches) that fell that month. The program should display a message similar to the following example:

The average rainfall for June, July, and August was 6.42 inches
How's this? If you want an easier to understand version, I'll try to make another one.
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
#include <iostream>
#include <string>
using std::cout; using std::cin; using std::endl;
using std::string;

struct month
{
	string name;
	float rainfall;
};

float average(const month& m1, const month& m2, const month& m3)
{
	return (m1.rainfall + m2.rainfall + m3.rainfall) / 3;
}

int main() 
{
	month m1{}, m2{}, m3{};
	
	cout << "Average Rainfall for 3 Months Calculator" << endl;
	cout << "Enter the first month: ";
	cin >> m1.name;
	cout << "Enter rainfall for " << m1.name << ": ";
	cin >> m1.rainfall;
	cout << "Enter the second month: ";
	cin >> m2.name;
	cout << "Enter rainfall for " << m2.name << ": ";
	cin >> m2.rainfall;
	cout << "Enter the third month: ";
	cin >> m3.name;
	cout << "Enter rainfall for " << m3.name << ": ";
	cin >> m3.rainfall;
	
	cout << "Average rainfall: " << average(m1, m2, m3) << endl;
	
	return 0;
}
Last edited on
thanks man this is pefect i undestand it perfectly
Topic archived. No new replies allowed.