Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I'm not a wiz at math and this problem has me a little stumped. I need the average score out of 5 but it's a little different how I do it.

I have 5 fields, field one is rating one, field two is rating two, all the way up to field 5.

I need to grab the average of all these fields together, this is currently what I have.

Sorry, it's in programming syntax

round((($rating_one / 5) + ($rating_two / 5) + ($rating_three / 5) + ($rating_four /5) + ($rating_five / 5) / 5));

So I divide each field by 5, and add them together and then divide the total amount of the fields for the average. The problem is I need it to be 1-5, and I keep getting 109.

Here are the numbers in the fields

13
432
42
33
23

What am I doing wrong? If you need more details, I'll happily provide (or try) more.

share|improve this question
    
Well, when you divide each field by $5$ and add them, you get the average of the fields. So it's definitely not their average or anything like it. So what you are doing is getting one fifth of the average. You may want to first scale the value of the fields so they are each out of $5$, then add them and divide by $5$. Do you know the range of each field (what are the possible values for field 1, field 2, etc.)? –  Arturo Magidin Apr 1 '11 at 16:01
    
Also: you aren't actually doing what you think you are doing, because your parentheses are in the wrong place. You are actually dividing each of the first four fields by 5, the last by 25, and then rounding the answer (check the parentheses). –  Arturo Magidin Apr 1 '11 at 16:08
add comment

1 Answer 1

up vote 1 down vote accepted

If you know the ranges for each field, the simplest thing is to first scale them so they are all out of $5$, and then average them.

To convert a quantity $Q$ that takes values between $a$ and $b$ to a quantity that takes values between $0$ and $N$ linearly, you compute $$\frac{N(Q-a)}{b-a}.$$ Note that $Q-a$ takes values between $0$ and $b-a$, so dividing by $b-a$ gives you a number between $0$ and $1$, and multiplying by $N$ gives you a number between $0$ and $N$.

Say the first field is takes values from $0$ to $N_1$, the second from $0$ to $N_2$, the third to $N_3$, the fourth to $N_4$, and the last to $N_5$ (which may or may not be different). Then to convert them to be out of $5$ and then averaging them, you can take $$\frac{\text{Field 1}}{N_1} + \frac{\text{Field 2}}{N_2} + \frac{\text{Field 3}}{N_3} + \frac{\text{Field 4}}{N_4} + \frac{\text{Field 5}}{N_5}.$$ If you then need it to be an integer, you can round; this may give you $0$ as the answer, which you may or may not want. (There is no multiplication and division by $5$ because here you have five fields, each out of five, so the multiplication and division by $5$ cancel each other out).

In general, for $k$ fields, you would take $$\frac{5}{k}\left(\frac{\text{Field 1}}{N_1} + \frac{\text{Field 2}}{N_2} + \cdots + \frac{\text{Field }k}{N_k}\right).$$

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.