d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Dumbass
Add Reply New Topic New Poll
Member
Posts: 6,775
Joined: Apr 25 2007
Gold: 1,413.94
Warn: 10%
Nov 16 2012 05:45pm
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++
Member
Posts: 4,605
Joined: Sep 15 2011
Gold: 9,464.00
Nov 16 2012 10:24pm
you have two functions with identical signatures. why?
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll