Code
//2. Write a function which is passed an array of int and its size, and prints out only the numbers that are above average.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
using namespace std;
void process(ifstream &in,char filename[]);
int main(){
char filename[200];
ifstream in;
cout<<"Enter input file name and path:\n";
cin.getline(filename, 200);
in.open(filename);
if(!in.is_open()){cout<<"Error.\n";exit(-10);}
process(in,filename);
cout<<"Process complete.\n";
in.close();
return 0;
}
void process(ifstream &in,char filename[]){
int count = 0, sum=0;
double average;
int number;
while(in>>number){
count++;
sum+=number;
average=(1.0*sum/count);
}
cout<<"Sum="<<sum<<"\nCount="<<count<<"\nAverage="<<average<<endl;
while(in>>number){ //doesnt work
if(number>average){
cout<<number<<" is greater than average.\n";
}
}
}
idk why that part doesnt work
i tried in.clear() and in.close() and in.open(filename, 200) and still it doesnt recognize that final while loop
forgot to mention.. C++