Ollie
Ollie

Reputation: 13

Is there a method for finding what number is needed to achieve an increment in an average

I am working on a personal project, and I need to calculate what increase in numbers will bump the average to the next increment, I am able to do this long winded with if statements but wondered if there is already an algorithm or method for this.

Example

Upvotes: 1

Views: 92

Answers (1)

jason.kaisersmith
jason.kaisersmith

Reputation: 9610

Not really a programming problem, maybe there are simpler Maths formulas, but the following works.

If you want to increase each number by the same amount then:

Multiply the average value you want to have by the number of elements

751 * 8 = 6008

Minus the sum of your existing elements and Divide by the number of elements

6008 - 6005.6 = 2.4

2.4 / 8 = 0.3

Each number needs to be increased by 0.3 to make your average 751.

If you want to just increment 1 number to increase your average then:

Multiply the average value you want to have by the number of elements

751 * 8 = 6008

minus all the existing numbers except the one you want to increase / last value. This will leave you with the new last value you should use.

Upvotes: 1

Related Questions