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?
#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?