Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

U ilaracter equiv. a table that indicates the rainfall for the city of Plainview

ID: 3736364 • Letter: U

Question

U ilaracter equiv. a table that indicates the rainfall for the city of Plainview and compares the cur- 5. Generat rent year's rainfall for the city with the rainfall from the previous year. Display su statistics that will indicate both the annual rainfall for each year and the average monthly rainfall for each year. The input data will consist of twelve pairs of numbers. The firs um- ber in each pair will be the current year's rainfall for a month, and the second be what fell during the same month the previous year. The first data pair will represent Jan- uary, the second will represent February, and so forth. If you assume the data begin 3.2 4 (for January) 2.2 1.6 (for February)

Explanation / Answer

Solution:

code:

#include<iostream>

#include <fstream>

#include <cassert>

#include <cstring>

using namespace std;

int main(){

ifstream infile; // file declared to take input from the file

cout << "Please enter the input file name> " << flush; //Asking for the filename

while (true)

{

string myFileName; // This is in which my file will be stored

getline( cin, myFileName );

infile.open( myFileName.c_str() );

if (infile) break;

cout << "Invalid file. Please enter a valid input file name> " << flush; // If the file is invalid

}

char ch;

string str1, str2;

double a, b, c, d, total=0, average=0; // Variable declaration

int year;

ofstream myFile ("rainFallOutput.txt"); // declaration of file in which output will be stored

if (infile.is_open())

{

infile>>year>>str1>>str2>>a>>b>>c>>d;

total= a+b+c+d; //Total RainFall

average= total/4;// Average of RainFall

}

cout<<" During "<<str1<<"-"<<str2<<" "<<year;

cout<<" Total rainfall was: "<<total<<" Average rainfall was: "<<average; // To display on console

myFile<<" During "<<str1<<"-"<<str2<<" "<<year;

myFile<<" Total rainfall was: "<<total<<" Average rainfall was: "<<average; // Writing the output into the file

return 0;

}

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)