# Specific average calculation [closed]

Suppose I have a set of weighted grades for a subject in high school. Like this: 8.4 (weight: 3), 7.2 (weight: 1), 3.4 (weight: 3). When I loop over that set like this:

totalCount: Double
totalWeight: Integer

totalWeight += weight
}
average = totalCount / totalWeight


That gives me the current average. Which is fine, but I want to calculate what grade I should score for a given weight to precisely get an average of 5.50.

That means I only want to calculate what grade I should score, as the user chooses the weight.

That means I should use this equalization: 5.50 = ((grade1 * weight1) + (grade2 * weight2) .... + (gradeToBeCalculated * givenWeight)). I'm not entirely sure how to do this in programming code, has somebody got examples for me?

## closed as off-topic by Jimmy R., JonMark Perry, Harish Chandra Rajpoot, Kamil Jarosz, SchrodingersCatJan 25 '16 at 18:01

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question is not about mathematics, within the scope defined in the help center." – Jimmy R., JonMark Perry, Harish Chandra Rajpoot, Kamil Jarosz, SchrodingersCat
If this question can be reworded to fit the rules in the help center, please edit the question.

The equation above is a linear equation in many variables, as only the weights are fixed and all the grades can vary.

If you have n variables, you need to have n independent equations to get a unique solution. The equation you have will probably have infinite solutions. However, as the range for grades is probably limited, it may have a unique solution or no solution for particular values of the weights.

EDIT

The question asks for how to get an overall average of 5.50 when one grade and one weight is added.

For this:

$5.50$ $=$ $($$total count(existing) + new grade * new weight$$)$ $/$ $($ $existing total weight$ $+$ $new weight$ $)$

Thus,

$new grade$ $=$ $($ $5.50$ $*$ $($ $existing total weight$ $+$ $new weight$ $)$ $-$ $total count$ $)$ $/$ $new weight$

• The weight per grade can actually vary from 1..n, but it's fixed as in: it is set at a fixed value by a teacher. The grades are also fixed by the teacher. The thing is, I want to add a grade to the equation as mentioned above, but I'm not sure how I should calculate what that grade should be with the weight given by the user. – Johann Behrens Jan 25 '16 at 9:31
• So that means I calculate the given set of grades with weights, the user inputs a weight and I just need to calculate which grade that user should score on the next test to get a 5.50 – Johann Behrens Jan 25 '16 at 9:32
• You mean the data is added one at a time and you want to know what grade you need for a given weight in a single test to make the overall value 5.50? – GoodDeeds Jan 25 '16 at 9:37
• Precisely, yes. I want the grade of that single test calculated for the average to be at least 5.50. – Johann Behrens Jan 25 '16 at 9:41
• I add one grade with the given weight and I want to know what value that grade should be in order for the average to be 5.50. – Johann Behrens Jan 25 '16 at 9:43