Program won't output to new file

Write your question here.
I have to write a program to read first value, and that is the number of numbers to be read next. I must calculate average of those numbers and write to an output file the numbers read and the average, and repeat this process until end of file.

The issue is my program is only averaging the first set of 4 numbers. It isn't doing anything after. It also is not outputting the information to an output file. Please help!

My input file looks like:
4 12 14 99 83 5 2 9 56 4 3 2 13 15 1 6 8 32 12 3 4 5 12 34 45

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  #include <iostream>
#include <fstream>

using namespace std;

int main()
{
	ifstream in;
	in.open("lab6input.dat");
	
	ofstream out;
	out.open("lab6output.dat");
	
	int num = 0;
	in>>num; 
	
	int temp = 0;
	int i=1;
	int total = 0;

	while(i<=num && !in.eof())
	{
		in >>temp;
		out<<temp;
		total = total + temp;
		cout<<temp<<" ";
		i++;
	}
	cout << "\n"<<"Average:"<<(double)total/num<<endl;
	
	out<<endl;
	out<<"Average:"<<(double)total/num<<endl;
	
	in.close();
	out.close();
	
	return 0;
}
Topic archived. No new replies allowed.