#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
usingnamespace std;
void main()
{
int num, fnum, lnum, sum;
float average, total, counter;
char inchar;
ofstream fileout;
ifstream filein;
filein.open("E:\\*****\\datafile2.txt");
fileout.open("E:\\*****\\answers.txt");
while(filein)
{
filein>>num;
fileout<<num<<" ";
}
total=0;
counter=0;
while(filein)
{
filein>>num;
total=total+num;
counter++;
average = total/counter;
fileout<<fixed<<setprecision(3)<<endl<<"The Average from the input file is: "<<average<<endl;
}
}
This class has me stumped currently and I am having a hard time breezing through the class at my instructors speed. So I don't want to get too far behind.
Right now this program is giving me an error that opens CMD and gives me infinite lines of "0's".
Ok, after doing some more work I have made my program read and write the document to the correct file. Although now in stage 2 of my lesson I need to make it compute the averages of the number. This although is my current output: