The best way to do this is probably just have two variables: a counter and a total. Make their scope module level (declared at the top). When the user inputs a number, add it to the total and increment the counter. When a user wants to see the average, just divide total by counter.