0
$\begingroup$

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

for grade in grades {
  totalCount += grade * weight
  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?

$\endgroup$

closed as off-topic by Jimmy R., JonMark Perry, Harish Chandra Rajpoot, Kamil Jarosz, SchrodingersCat Jan 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.

0
$\begingroup$

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$

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Johann Behrens Jan 25 '16 at 9:31
  • $\begingroup$ 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 $\endgroup$ – Johann Behrens Jan 25 '16 at 9:32
  • $\begingroup$ 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? $\endgroup$ – GoodDeeds Jan 25 '16 at 9:37
  • $\begingroup$ Precisely, yes. I want the grade of that single test calculated for the average to be at least 5.50. $\endgroup$ – Johann Behrens Jan 25 '16 at 9:41
  • $\begingroup$ 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. $\endgroup$ – Johann Behrens Jan 25 '16 at 9:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.