Thread: daily average

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    8

    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. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    8
    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. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    You'd have to maintain the values of the totals by hour in your program.
    Sent from my iPadŽ

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    8
    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. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    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?
    Sent from my iPadŽ

  8. #8
    Registered User
    Join Date
    Dec 2005
    Posts
    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. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    So again, why is this hard?

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

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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. #11
    Registered User
    Join Date
    Dec 2005
    Posts
    8
    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. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Last edited by quzah; 12-02-2005 at 03:55 PM.
    Hope is the first step on the road to disappointment.

  13. #13
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    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*
    Sent from my iPadŽ

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I have a nice cold drink, but thanks for the thought. On an aside, they don't pay me to be nice.


    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    Registered User
    Join Date
    Dec 2005
    Posts
    8
    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 subscribe to a feed

Similar Threads

  1. C program using structs to calculate grades
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-06-2009, 12:33 PM
  2. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  3. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  4. Average score
    By wiz23 in forum C++ Programming
    Replies: 22
    Last Post: 05-05-2005, 05:38 AM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM