hello, I have to write a program that takes floating point numbers from another file and prints out the average. The problem is the other file submits three columns so I don't know how to do the average for the three separate columns.
This code is terrible and I can't figure out how to do it. any help?
Thanks!
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ( ){
double number (0),sum(0);
int nCount(0);
string filename;
ifstream fin;
cerr << "Enter the File Name ";
cin >> filename;
fin.open( filename.c_str( ) );
if( fin.fail( ) ) {
cerr << "ERROR FILE COULD NOT BE OPENED " << filename << endl;
exit( -1 );
}
cout << number;
sum += number;
number_count++;
cout << "\nThe average for the sequence of numbers above is: " << sum/nCount << endl;
cout << endl;
fin.close();
return 0;
}