Question : Average of numbers

I believe this is pretty easy, but I can't figure it out.  I would like people to be able to rate something on a scale of say 1 to 5.  What's the most effective way of storing the average of this?  For example should I store how many people voted for 1, 2, etc and then calc the total votes and average based on this?  Or would I simply be able to store the average and how many total votes there have been?  Whichever way is better, or if you know of any other ways, could you say here, and show an example of computing the average?  Thanks for any advice and feel free to ask any questions.

Answer : Average of numbers

I would suggest that you store the total (ie. if someone voted '3', then '3' would be added to the total. Every time someone votes, add one to the vote count. It's then a simple matter of dividing the 'vote total' by the 'vote count' to get the average. you may want to store the variables for the 'vote total' and the 'vote count' in a text file so that they will be stored even if your server goes down.
Random Solutions  
 
programming4us programming4us