Lab 5 - Practice with Loops

Due - November 1/2, 2004

In this lab, you will write a program that uses while and for loops. Your program will prompt the user for a series of positive numbers and calculate the largest, smallest, and average of the numbers. First, you must ask the user whether she knows how many numbers are in the series she plans to enter. If she responds yes (y), use a for loop to prompt her for the series of numbers. When she has entered all numbers, output the largest and smallest numbers entered as well as the average of the numbers. If she responds no (n), use a while loop to prompt her for numbers until she enters 0, the sentinel. After she enters 0, output the largest and smallest numbers entered as well as the average of the numbers. Following are two examples of runs of your program:

Example 1: User knows how many numbers are in the series.

Welcome!
Do you know how many numbers you would like to enter? y
How many numbers would you like to enter? 6
Enter number 1: 33
Enter number 2: 12
Enter number 3: 15
Enter number 4: 77
Enter number 5: 34
Enter number 6: 10
The largest number you entered is 77.
The smallest number you entered is 10.
The average of the numbers you entered is 30.167.

Example 2: User does not know how many numbers are in the series.

Welcome!
Do you know how many numbers you would like to enter? n
Enter number 1: 33
Enter number 2: 12
Enter number 3: 15
Enter number 4: 77
Enter number 5: 34
Enter number 6: 10
Enter number 7: 0
The largest number you entered is 77.
The smallest number you entered is 10.
The average of the numbers you entered is 30.167.

Implementation Hints

If the user enters a negative number, print an error message and continue without doing any comparison.

If the user indicates that she knows how many numbers she would like to compare but indicates that she would like to compare 0 or fewer numbers, print an error message and ask the user for a different number. Do this until the user enters a positive number.

Part 1 - Due - Monday, October 25, 2004 - 8:35AM

Submit a program design and series of test cases.

Part 2 - Due - November 1/2, 2004 - Beginning of Lab

Submit your completed code.
  1. Make sure that each function is well documented. Your documentation should specify the type and role of the input paramaters and ouput.
  2. Copy and paste the output of your program to the bottom of your program itself. Make sure the output is a comment. That means, put a /* before the output and a */ after the output.

Sami Rollins