mol
October 12th, 2001, 04:59 PM
Check it out:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void main()
{
int count;
float num;
float total;
float 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();
inData.open("datfile1.txt");
count = 0;
avg = 0;
total = 0;
outData << fixed << showpoint
<< setprecision(3);
while(inData >> num)
{
total += num;
cout << total << " " << num << endl;
count++;
}
cout << total << endl << count;
avg = total / count;
outData << avg << endl;
inData.close();
}
This is school crapola. I have to use two loops (if I could do it the proper way I wouldnt be having a problem) anyway, it just doesnt perform the second loop. If you comment out the first loop, then the second one works.
I just dont get it.
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void main()
{
int count;
float num;
float total;
float 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();
inData.open("datfile1.txt");
count = 0;
avg = 0;
total = 0;
outData << fixed << showpoint
<< setprecision(3);
while(inData >> num)
{
total += num;
cout << total << " " << num << endl;
count++;
}
cout << total << endl << count;
avg = total / count;
outData << avg << endl;
inData.close();
}
This is school crapola. I have to use two loops (if I could do it the proper way I wouldnt be having a problem) anyway, it just doesnt perform the second loop. If you comment out the first loop, then the second one works.
I just dont get it.