Question: rewrite this program without using an array. Calculate the average,then close and reopen the input file and count the number of values greater than the

rewrite this program without using an array. Calculate the average,then close and reopen the input file and count the number of values greater than the averages.

so far this is what i have for the question. but the averages dont seem to work when using a txt file

#include #include #include using namespace std ; int main() { //define max array size constant

const int N = 100 ;

//declare and initialize objects string filename ; int count=0, numberOfValues ; double y , yAve , sum=0 ; ifstream lab; //prompt user for name of input file cout<< "Enter name of the input file " ;\ cin>> filename ; //open data file and read data into an array //compute a sume of the values. lab.open(filename.c_str()) ; if (lab.fail()) { cerr << "error opening input file " ; return (1);

} /*file has been opened. */ /* read number of data values. */ lab >>numberOfValues ; //dont exceed the bound of the array. if(numberOfValues > N) { cerr << "Number of data values." <

} int k; for (k=0; k

lab >> y; sum += y; } //compute average and count values that are greater //than the average. yAve = sum/numberOfValues; lab.seekg(0, ios::beg); lab >>numberOfValues ; for (k=0; k> y; if(y>yAve) count++; } //print count. cout << count << " values greater than the average "; //close file and exit program. lab.close(); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!