November 28th, 2012, 08:53 PM

Help! Averaging weekly values from a file
Basically i have an assignment where i have to read information from a text file that has a month of data and use it to find different averages and min and max values etc.
The problem is that i am not sure how to figure out the average for just one week since the information in my file is for one month.
I figured out how to read the file and how to do monthly averages but i am not sure how to do it for just one week.
This is what i have so far (i decided to do a loop):
count = 0;
double weekOneAveragePressure;
double sumWeekOneAveragePressure = 0;
while (count<counter){
sumWeekOneAveragePressure += Pressure[count];
if (count<6)
sumWeekOneAveragePressure += Pressure[count];
else if (count==6)
weekOneAveragePressure = (sumWeekOneAveragePressure / count);
count++;
I start by resetting the count to zero cause i used it to calculate monthly averages. The counter was also declared before in a try and catch statement where the file reading and array declarations take place.
What would i have to add and fix to the code to make it calculate the average of just one week (7days)?
November 28th, 2012, 09:44 PM

how to do it for just one week
Have a counter for weekly data. Reset it to 0 at the start of every week.
November 29th, 2012, 07:06 AM

The 7 day can work if you have records for saturday and sunday also, because if your week is only monday to friday it won't work.
But first of all how is the data organized?
By days? or Simply a complete month data?
November 29th, 2012, 10:34 AM

Its organized from a separate text file, which has 30 different numbers for each of the seven categories (pressure, temperature, etc) and are seperated by commas.
Like this:
01,0.475,19.5,149.0,30,92,No
02,0.480,20.5,142.0,28,96,No
03,0.505,19.1,152.0,39,72,Yes
04,0.425,22.5,143.0,31,90,No
05,0.528,18.2,140.0,42,69,Yes
06,0.490,18.3,138.0,34,99,No
07,0.498,23.1,141.0,37,82,Yes
.......etc.
November 29th, 2012, 10:36 AM

Can you tell when the data for each week starts?
November 29th, 2012, 11:01 AM

Basically the data is everything in each column. Each column has 30 numbers which represents one month. Somehow i am supposed to break it down into weeks and calcucate the averages for each week.
This is my code for calculating a monthly average for the column which represents data for pressure:
double averagePressure;
double sumPressure = 0;
int count = 0;
while (count<counter)
{
sumPressure += Pressure[count];
count++;
}
averagePressure = (sumPressure / count);
November 29th, 2012, 11:12 AM

Each column has 30 numbers which represents one month.
Does each column represent the data for a day? What about the months with 31 or 28/29 days?
You need to know what each piece of data represents.
In post#4 each line starts with a new number that looks like a row number. What is the first value on each line? How many lines are in the file? Are they all numbered as shown in post#4?
Last edited by NormR; November 29th, 2012 at 11:14 AM.
November 29th, 2012, 11:24 AM

Originally Posted by NormR
Does each column represent the data for a day? What about the months with 31 or 28/29 days?
You need to know what each piece of data represents.
The data is just for one month (september; which has thirty days.
The first column represents the days, second column represents pressure, third represents highest temperature, fourth represents lowest temperature, fifth is for wind speed, sixth is for battery power, and seventh is a true/false thing (boolean).
So each row would represent the data for all types each day.
November 29th, 2012, 11:33 AM

How do you tell which data is for the each day of the month?
Does the first column have the day of the month?
Then are days 01 to 07 one week of data?
And 08 to 14 are the second week of data?
Can you explain what your problem is with determining when a week starts?
Would the first week start at day 01 and the second week start with 08?
November 29th, 2012, 11:36 AM

Originally Posted by NormR
How do you tell which data is for the each day of the month?
Does the first column have the day of the month?
Then are days 01 to 07 one week of data?
And 08 to 14 are the second week of data?
Can you explain what your problem is with determining when a week starts?
Would the first week start at day 01 and the second week start with 08?
Yes and my issue is that i dont know how i would find out the averages for those 7 days and then the averages for 814
November 29th, 2012, 11:39 AM

how i would find out the averages for those 7 days
Add up the daily values for the 7 days and divide by 7