#include<iostream> #include <string> #include <fstream> #include <iomanip> using
ID: 3610863 • Letter: #
Question
#include<iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const int SIZE = 25;//Size of arrays
int main()
{
double SalesAmounts [SIZE]; //Sales amounts array
string SalesReps [SIZE]; //Names of sales representativesarray
ifstream infile; //Input filestream variable
string fnameopen, fnameclose; //Variables to hold actualname of file
double sum;
int counter; //used in for loops
double average; //average of sales amount
cout<<"Pleaseenter name of input file"<<endl;
cin>>fnameopen;
infile.open(fnameopen.c_str());
cout<<"Please enter name of outputfile"<<endl;
cin>>fnameclose;
sum = 0;
for (counter=0; counter<SIZE; counter++)
{
cin>>SalesAmounts[counter];
sum = sum +SalesAmounts[counter];
average = sum/SIZE;
}
cout<<fixed<<showpoint<<setprecision(2);
cout<<"Average slaes: "<<setw(7)<<"$"
<<setw(7)<<average<<endl;
Explanation / Answer
please rate - thanks problems: you were reading from cin (keyboard) not file don't have 25 records(probably) but reading 25 calculating average in loop and dividing by 25 should calculate outside loop and divide by # of #'s not inputting name #include #include #include #include using namespace std; const int SIZE = 25; //Size of arrays int main() { double SalesAmounts [SIZE]; //Sales amounts array string SalesReps [SIZE]; //Names of sales representativesarray ifstream infile; //Input filestream variable string fnameopen, fnameclose; //Variables to hold actualname of file double sum; int counter=0; //used in for loops double average; //average of sales amount coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.