Current code: avg = (Σ unit_cost_i) / (# of products) Fix: avg = (Σ qty_i * unit_cost_i) / (Σ qty_i) Which more accurately represents the actual case.