donmiq 0 Newbie Poster

Hello, I have an assignment to copy contents of a file (txt), and output it in the destination file which is also a text file. While (or after?) that is done, it needs to output the average of each line, which does not have a constant amount of numbers per line. Before I get too carried away, let me say I don't want the work to just be done for me, I want to solve it myself, but with some help because I am completely lost. This is an example of what the assignment wants.
source file:

3 3.3 1.1 2.2
5 1 2 3 4 5
1 7
2 12 12

output file:

3 3.3 1.1 2.2 Average 2.2
5 1 2 3 4 5 Average: 3
1 7 Average: 7
2 12 12 Average: 12

Keep in mind this can be formatted in any way. The first number in every line is the amount of numbers to be averaged. I have only been able to output the "Average: 2.2" in the output file. I am not aware of how to do multiple lines, although I know there is a way. I also don't know how to output the original information followed by the average. Let me show you what I have so far:

int main()
{
	string inputFile;
	string outputFile;
	ifstream fin;
	cout << "What is the input file? " << endl;
	getline (cin, inputFile);
	fin.open (inputFile);
	if (!fin)
	{
		die ("Can't open " + inputFile);
	}
	cout << "And the output file? " << endl;
	getline (cin, outputFile);
	ofstream fout;
	fout.open (outputFile);
	if (!fout)
	{
		die ("Can't open " + outputFile);
	}
	unsigned numPerLine[1];
	double average = 0;
	double sum = 0;
	unsigned count = 0;
	fin >> numPerLine[0];
	for (unsigned i = 0; i < numPerLine[0]; i++)
	{
		double a;
		fin >> a;
		sum += a;
	}
	fout << "Average: " << sum / numPerLine[0] << endl;
}

As you can see, It can do the first line of whatever is there, but after that I haven't the slightest clue. I tried a nested loop to input the next line's number amount but it gives unwanted results. Any suggestions or tips to push me in the right direction would be greatly appreciated. Thanks in advance.