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

Create a C++ program to read in a file of monthly rainfall values (in inches) an

ID: 3538039 • Letter: C

Question

Create a C++ program to read in a file of monthly rainfall values (in inches) and display a formatted table of results. Each line in the input file will contain one integer and two floats representing the month, average, and actual rainfall. Your program should read the values into three arrays. Month integers: month array, monthly average rainfall, average array, monthly actual rainfall, actual array. The program output should be a nicely formatted table showing the month name, average rainfall, actual rainfall, and the dierence. Above average rainfall should be displayed as a positive number and below average rainfall should be dsiplayed as a negative number (with minus sign). Rainfall amounts should be display with two digits after the decimal. A partial sample of the output is shown below.

Explanation / Answer

please rate - thanks


any questions just ask



# include <iostream>
#include<fstream>
#include<iomanip>
using namespace std;
int main ()
{int i=0;
char filename[30];
char name[12][10]={"January","February","March","April","May","June","July","August",
                    "September","October","November","December"};
int month[12];
float average[12],actual[12];
ifstream in;
cout<<"what is the name of the file you are using? ";
cin>>filename;
in.open(filename);           //open file
if(in.fail())             //is it ok?
       { cout<<"file did not open please check it ";
        system("pause");
        return 1;
        }
cout<<"    Month Average Actual Difference ";
for(i=0;i<12;i++)
    in>>month[i]>>average[i]>>actual[i];
for(i=0;i<12;i++)    
     cout<<setw(10)<<name[month[i]-1]<<fixed<<setprecision(2)<<" "<<average[i]<<" "
         <<actual[i]<<" "<<actual[i]-average[i]<<endl;
    
in.close();
system("pause");
return 0;
}