Why make it the hard way. It is too complicated / error prone and probably wrong. It is so easy to add few values and divide by number of the values.