gray 0 Newbie Poster

Hie
I have got a problem , the problem I cannot extract the values from a file (eg I created a file called gray.txt for extraction
and a file called average.nbr for insertion) the program is running but if I check in the file average.nbr there is nothing
written.

here is the program:

// Prompts user for a file and then calculates
// the average of the values in that file
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;


int main() {
cout << "File of values to be averaged: ";
string FileName;
cin >> FileName;
ifstream fin(FileName.c_str());
if (! fin) {
cerr << "Cannot open " << FileName
<< " for averaging." << endl;
exit(1);
}
int ValuesProcessed = 0;
float ValueSum = 0;
float Value;
while (fin >> Value) {
ValueSum += Value;
++ValuesProcessed;
}
if (ValuesProcessed > 0) {
float Average = ValueSum / ValuesProcessed;
ofstream fout ("average.nbr");
fout << Average << endl;
}
else {
cerr << "No values to average in "
<< FileName << endl;
exit(1);
}
return 0;
}

Output
Press any key to continue...

Help!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.