Advertising
- Someone
- Wednesday, May 9th, 2007 at 4:15:42pm MDT
- int *curr_val;
- int history[5];
- curr_val = history; // point to the first element of history
- // to get a new element:
- *curr_val++ = get_new_value();
- // make sure to wrap at the end of the history array
- // alternatively, replace the pointer with an index value and access the array through that
- if(curr_val > &history + 5) curr_val = history;
- // for getting the average sum up all values in the array history
- int avg;
- avg = 0;
- for(int i = 0; i < 5; i++) avg += history[i];
- avg /= 5;
- // now avg has the average of the last 5 elements, including the value we gathered at the start of this snippet
- get_new_value = whatever I want to add, such as data or w/e right? followed by a ()
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.