added a second way to compute the average using a foreach loop.