Ok. Be a little gentle. Im coming from microprocessor background so file i/o is a bit new to me. Anyway, here is some code below. Its pretty simple, its reading a file that has multiple lines of ints in it. It writes all the ints to the output file on one line. Then it is SUPPOSED to read the file again, this time computing the average and outputting it on the next line.

But, in the debugger I get a divide by 0 error...so something is wrong with the i/o operation. *sigh*

Can anyone lend a hand?

PHP Code:

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

void main()
{
    
int count;
    
int num;
    
int total;
    
int avg;

    
ifstream inData;
    
ofstream outData;

    
// lets get them all on one line
    
inData.open("datfile1.txt");
    
outData.open("outdata.txt");

    while(
inData >> num)
    {
        
outData << num << " ";
    }

    
outData << endl;

    
inData.close();

    
// lets get the avg of all ints in the file
    
    
inData.open("datfile1.txt");

    
count 0;
    
avg 0;

    while(
inData >> num)
    {
        
total += num;
        
count++;
    }
    
    
avg total/count;
    
outData << avg << endl;

    
inData.close();