CS21 Week2 In-Class Exercises

  1. Copy the program you wrote for the last homework which read in four numbers and computed their average. Change it so that the program begins by asking the user for the number of values to average. An example of executing the new version is shown below:
    This program averages a list of integers.
    How many values are there in the list? 5
    ? 95
    ? 100
    ? 89
    ? 91
    ? 97
    The average is 94.4
    

  2. Write a program that reads in a list of integers until the user enters the value -1 as a sentinel. At that point, the program should display the average of the values entered so far. Your program should be able to duplicate the following sample execution:
    This program averages a list of integers.
    Enter -1 to signal the end of the list.
    ? 95
    ? 100
    ? 89
    ? 91
    ? 97
    ? -1
    The average is 94.4