han isn't letting me send PMs - keeps telling me i'm not logged in. anyways yeah, it compiles and runs fine. the only exception being that it seems to cut off trailing zeros, whereas the sample solution you posted doesn't. eg, "4.10" becomes "4.1" in the output files. anyways, i did tell you exactly what i did, but since you still can't figure it out, here it is.
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main() {
ifstream fin;
ofstream a;
ofstream b;
fin.open("input.txt");
if (fin.fail())
{
cout << "file 'input.txt' failed to open.";
exit(1);
}
double weight;
int count = 0;
double sum = 0;
double average;
char group;
a.open("groupA.txt");
b.open("groupB.txt");
while (!fin.eof())
{
fin >> group;
if (group == 'A')
{
while (count < 10)
{
fin >> weight;
sum = sum + weight;
a << weight << " ";
count++;
}
average = sum / count;
a << "average = " << average << endl;
count = 0;
sum = 0;
}
if (group == 'B')
{
while (count < 10)
{
fin >> weight;
sum = sum + weight;
b << weight << " ";
count++;
}
average = sum / count;
b << "average = " << average << endl;
count = 0;
sum = 0;
}
}
a.close();
b.close();
fin.close();
}