All problems

Weighted Survey Score Divided by Response Count

Level 2 · node · Correctness · Incorrect denominator in weighted mean

Scenario

A fictional education survey service computes overall satisfaction from question scores and importance weights. Surveys with all weights set to one appear correct, but differing weights produce inaccurate report scores because the service divides the sum of weighted scores by the number of responses.

Requirements

Compute the weighted mean by dividing the sum of score-times-weight products by the total weight. Weights are nonnegative numbers. Return zero when the total weight is zero or there are no responses.

Acceptance criteria

  • Weights of one give the ordinary mean.
  • Different weights use the sum of weights as the denominator.
  • An item with zero weight has no effect on the result.
  • An empty response array returns zero.