### Getting averages from data from txt file

I have been given a text file that contains 365 lines, 1 number on each line. Each number is the amount of steps someone took per day for a whole year. The task is to calculate the average number of steps per month, using the daily amount of steps. I am completely stumped. I have no idea how I would take chunks of information from the file (lines 1-31 for january, lines 32-62 for february, and so on). The for loop is still a little confusing to me. Someone else that created this program said they used a while loop with a nested for loop, but I cannot picture how that would work out. This is literally all I have so far.
 ``1234567891011121314151617181920212223242526272829303132333435363738`` `````` This program displays the average number of steps taken per month, based on information from a text file. */ #include #include #include using namespace std; int main() { ifstream inputFile; // Amount of days for each month /* Jan, Mar, May, July, Aug, Oct, Dec = 31 days Apr, June, Sept, Nov = 30 days Feb = 28 days */ int avg, days, value; // Open the file inputFile.open("steps.txt"); return 0; }``````
Last edited on
 I have no idea how I would take chunks of information from the file

http://www.cplusplus.com/doc/tutorial/files/
Last edited on
There's no need to look too far ahead. Build up the code in stages.

First read a single value from the file. Write the code, test it.

When you have that working, try to read 31 values from the file. Calculate their average. Write the code, test it.

When you have that working, start to consider how you might enclose what you have so far within an outer loop.