User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,583 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,596 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1797 | Replies: 0
Reply
Join Date: Jun 2004
Location: Zimbabwe
Posts: 6
Reputation: gray is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gray gray is offline Offline
Newbie Poster

Solution file extraction and insertion

  #1  
Aug 18th, 2004
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!!!!!!!
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 6:27 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC