need help with my c++ hw, using fstreams

so i'm new with this fstream thing basically i have to get my c++ to use a the following numbers from an outside .txt file

5 96 87 78 93 21 4 92 82 85 87 6 72 69 85 75 81 73

i need my program to calculate and display the average of each group of numbers. so when the number is 5, that indicates the next 5 numbers that should be grouped together, when the number is 4, that groups the next 4 numbers, and when its 6, it groups the 6 next numbers. the book gave a hint that we should use a nested loop. the outer loop should terminate when the end of the file has been encountered. i honestly don't know how to start this thing. this is what i have so far.

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	ifstream theFile("homework.txt");

	int numbers;

	while(theFile >> numbers)
	{
		cout << numbers << " ";
	}
	

	system ("pause");
}


so far i can only get all the numbers out from the text file into my program but then im confused from there.

can you guys point me out what i should do next? and would vectors help for this program?
here is a website that might help you:

http://www.cprogramming.com/tutorial/lesson10.html
that website just gives me an overview of fstream, but it didn't really help on what i need...
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	ifstream theFile("homework.txt");

	int counter = 0;
	int numbers[18]; 

	while (counter < 18)
	{
		theFile >> numbers[counter];
		cout << numbers[counter] << " ";
		counter++;
	}

	system ("pause");
}


so pretty much i got my txt file into an array which will store the numbers and now i gotta figure out what to do from there, would a if statement work for the next step?
Topic archived. No new replies allowed.