Hello, I'm trying to loop through a .dat file and calculate the average of a group of numbers. Here is what the data looks like. So essentially I am trying to skip certain numbers out of the data file. The numbers in  indicate the following numbers to be averaged together. However, I'm having troubles just learning how to loop through the data file.
//Use for loop once counter reads first number (5)
if (count == 1);
for(i = 1; i < 5; i++)
inFile >> num1;
cout << num1 << endl;
the comment reads //Use for loop once counter reads first number (5)
1) but you are not reading any number
2) counter will turn 1 inside while and then the for loop will just read 5 numbers blindly (if it does read any,  in the example is not a valid number). If I get correctly then you need to read how many numbers to read and average then read those many numbers
3) This way the loop will be an infinite loop if there are more than 5 numbers in the file, after count becomes 2 the for loop will never get executed and hence the inFile >> num will never will get executed and the inFile.good() will be always true
Read the first 5 numbers after the  - calculate average (it's not entered like that in data, I only put brackets so it'd be easier to read). Then read the next 4 numbers after the  and calculate average. Then read the final 6 numbers after  and calculate average.
I'm not so much concerned with skipping the numbers as I am just getting this damn loop to work, been trying so many variations for hours. It's frustrating.
1 2 3 4 5 6 7 8 9 10 11
for (int i = 0; i < 5; i++)
number = inFile.get();
total = number + total;
No matter what the counter is, int i = 0; i < 1; ... it always reads the entire file!!
So essentially I am trying to skip certain numbers out of the data file.
I'd consider that isn't the best way of viewing the problem.
From my point of view, the numbers which you 'skip' are the key to understanding the contents of the file, and should therefore be read and used to control the subsequent processing. In the code below, the count variable is used for those important numbers. The numbers to be averaged are read into number.
I wrote this based upon the input data, I've not studied the previous code, so I'm not sure how helpful this will be.
(I used a stringstream in this example, but a normal file should work in the same way).