Lab 5 - Practice with Loops

Due - March 12, 2004

In this lab, you will write a program that uses while and for loops. The first part of your program will prompt the user for a series of positive integers and will read in each number using a while loop. When the user enters 0, your program will print the greatest number entered.
The second part of your program will ask the user for a number which will indicate the number of numbers the user wants to compare. Using a for loop, read in each number and print the smallest number entered. An sample run of your program follows:
Enter a postive number (enter 0 to quit): 3
Enter a postive number (enter 0 to quit): 6
Enter a postive number (enter 0 to quit): 72
Enter a postive number (enter 0 to quit): 19
Enter a postive number (enter 0 to quit): 0
The largest number you entered was 72.
Enter the number of numbers you would like to compare: 4
Enter a positive number: 12
Enter a positive number: 22
Enter a positive number: 64
Enter a positive number: 21
The smallest number you entered was 12.
Thanks for playing.

Your program should adhere to the following requirements:
  1. If the user enters a negative number, print an error message and continue without doing any comparison.
  2. While the user indicates she would like to compare 0 or fewer numbers (for the second portion of the program), print an error message and ask the user for a different number.
After you complete your code:
  1. Make sure that each function is well documented. Your documentation should specify the type and function of the input paramaters and ouput.
  2. Make sure a lab assistant (Dianne or I) has seen your program run.
  3. 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.

Extra Credit

For extra credit, print the index of the number that was largest/smallest. For example, your output might look like the following:
Enter a postive number (enter 0 to quit): 3
Enter a postive number (enter 0 to quit): 6
Enter a postive number (enter 0 to quit): 72
Enter a postive number (enter 0 to quit): 19
Enter a postive number (enter 0 to quit): 0
Your third number was 72 and it was largest.
Enter the number of numbers you would like to compare: 4
Enter a positive number: 12
Enter a positive number: 22
Enter a positive number: 64
Enter a positive number: 21
Your first number was 12 and it was smallest.
Thanks for playing.

For this portion, you can assume that the user will never enter more than 10 numbers.
Sami Rollins