Answer to Question #55086 in C++ for kklljjll
Write a program that reads in from a ﬁle a starting month name, an ending month name,
and then the monthly rainfall for each month during that period. As it does this, it should
sum the rainfall amounts and then report the total rainfall and average rainfall for the
period. For example, the output might look like this:
During the months of March–June the total rainfall was 7.32 inches and the average
monthly rainfall was 1.83 inches.
Data for the program can be found in the Rainfall.txt ﬁle.
Hint: After reading in the month names, you will need to read in rain amounts until
the EOF is reached, and count how many pieces of rain data you read in.
Please use notepad to create rainfall.txt with following data.
2.35 1.15 2.03 1.41
using namespace std;
int generate_stars(int n);
void read_and_count_rainfalls(string file_name);
string file_name = "rainfall.txt";
void read_and_count_rainfalls(string file_name)
string first_month, last_month;
vector <double> month_rainfall;
double total = 0, average = 0;
file >> s_temp;
temp = atof(s_temp.c_str());
total += temp;
average = total / month_rainfall.size();
cout << "During the months of " << first_month << "-" << last_month << " the total rainfall was "
<< total << " inches and the average monthly rainfall was " << average << " inches" << endl;
Need a fast expert's response?Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!