# Thread: daily average

1. ## daily average

Hello, I am trying to find out how to write a program which will take the average over the day. I dont want it to just take the average over the last 24 hours, I know how to do that, rather I want to find the average from 12 midnight to 12 midnight the next day, and to have this average displayed throughout the day and changing as the day progresses. This is to be written in C code

2. So rather than summing 24 values, and displaying the average, just create a loop which sums 1, 2, 3, 4, ... 24 values, and displays the average (24 times)

3. But how do I make sure it starts at 12 and ends at 12, i dont want it to just start wheneverr the program starts

4. You'd have to maintain the values of the totals by hour in your program.

5. Average from what? Where are you getting whatever it is you're averaging? And why on earth is this hard to figure out? Pick a point, stop 24 iterations later.

Quzah.

6. I am measureing the voltage coming from a solarimeter. I am having difficulties because I want it to start over at midnight no matter what time I start the program. If I was to just average over 24 hourly samples as you rudely suggested, then it would depend on the time I started running the program for when it would stop averaging. I stated I do not just want it over a random 24 hour period in my original post, I know how to do that.

7. As I said, you'd have to maintain the voltage levels hour by hour. For instance, if you wanted to start your program at 5pm today, you'd have to have hourly readings starting from the beginning of yesterday going to the beginning of today.

Are you planning on starting the program and using it to keep track of the voltage then 24 hours later, after running all day, it comes to a result, or are you planning on starting it and it has data stored for the past 24 hours?

8. Thanks, I am trying to have it keep a running average over the day beginning whenever i turn the program on so that whenever you want you can view the average for the day so far for that day. But i want the average to return to zero at midnight if it is left running for a longer period of time

9. So again, why is this hard?

1 - Get the current time.
2 - Average from midnight to now.
3 - Wonder why this is hard.

Quzah.

10. So when you first run the program, you call time() and localtime() to find out what the time really is now.
Then work out how long to sleep until the next hour (or midnight)
Then take a sample measurement.

11. Thanks for those who actually helped and tried to understand what I was asking, noone actually gave me information I used, but I figured it out on my own. I actually decided it was more benificial to my project to just sum it from midnight to midnight. Heres how I got it to work if you're interested:

Code:
```GetSystemTime (&hour, &minute, &second);

if((hour == 0 ) & (datecount == 0))
{

datecount = 1;
sumday = 0;

}

if (hour != 0)
{

sumday = (sumday + radiation);
datecount++;
result = SetCtrlVal(mainpanel, MAINPANEL_SUM_DAY, sumday);
datecount = 0;

}```

12. Oh, you mean just like we told you to do? Sum up 24 items... You know, where you whined that we weren't helpful, and didn't want to do it that way. Yeah, just like we said to do.

You might want to fix this:
Code:
`if((hour == 0 ) & (datecount == 0))`
& is not &&.

& is bitwise AND
&& is a logical AND

There's a difference.

See, you really didn't do a whole lot for your case here. You just said "I need to track something." To which we replied, "Um, ok, so track it." Then you cried that no one helped you. Well, you never said how your data was stored. How you were getting it, to look from. See, you could benifit from something like a FAQ on how to ask smart questions.

Your problem isn't a problem at all. It's so ........ing easy, I can't even call it a problem. Seriously, look at it.

I have a set of data D, stored anywhere, it doesn't matter. Given a time now, N, and a point to start S, average N - S items. "Oh gosh! That's tough! How Mr. Wizard?"
Code:
```for( sum = 0, count = 0; count + S < N; count++ )
{
sum += getdataforthisfreekinghour( S + count );
}
average = sum / count;```
"Holy semantics, Batman. You never cease to amaze me!"
"No time for compliments, Robin. We must thwart some criminals. To the Batmobile!"

Your problem is that you don't listen to people, and you can't form a question to save your life.

Quzah.

13. I'm thinking Quzah should team up with Maddox to form the meanest rant page in the universe.

*gives Quzah a nice cold drink to let off the steam*

14. I have a nice cold drink, but thanks for the thought. On an aside, they don't pay me to be nice.

Quzah.

15. Quzah,
Except for I didnt just sum up 24 things, that was the whole question I was trying to ask and all you could do was tell me how to average over 24 hours. Which is what I said several times was NOT WHAT I WANTED.

Popular pages Recent additions