Added deallocation of allocated memory and enhanced the program to average more than one record