Write a program that reads in from a %uFB01le a starting month name, an ending m
ID: 3538588 • Letter: W
Question
Write a program that reads in from a %uFB01le 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%u2013June 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 %uFB01le.
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.
The Rainfall.txt contains the following information:
Explanation / Answer
please rate - thanks
your sample output, was not the sum and average of your sample data
any questions-ask
# include <iostream>
#include<fstream>
#include<iomanip>
#include <string>
using namespace std;
int main ()
{int i=0;
double sum=0,average,amt;
string start,end;
ifstream in;
in.open("rainfall.txt");
if(in.fail())
{ cout<<"input file did not open please check it ";
system("pause");
return 1;
}
in>>start;
in>>end;
in>>amt;
while(in)
{sum+=amt;
i++;
in>>amt;
}
cout<<"During the months of "<<start<<" to "<<end<<" The total rainfall was "
<<sum<<" inches and the average rainfall was "<<sum/i<<" inches ";
in.close();
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.