Can anyone tell me why my fuction does not return anything when the program is run? It compiles correctly but it wont output anything...
Code:#include <iostream.h> // for output to screen #include <fstream.h> // for file I/O #include <stdlib.h> // for exit function void read_file(ifstream& fin, double& sum, double& count); void main() { double sum=0; // accumulates sum of values in file double count=0; // counts number of values read ifstream fin; // input file stream fin.open("input.dat"); if (fin.fail()) { cout << "Error opening file input.dat\n"; exit(1); } read_file(fin, sum, count); } void read_file(ifstream& fin, double& sum, double& count) { int next; fin >> next; while (!fin.eof()) { count++; sum += next; fin >> next; } cout << "Number of values read: " << count << endl; cout << "Sum of values read: " << sum << endl; cout << "Average value: " << sum/count << endl; }



LinkBack URL
About LinkBacks


