Homework 5: More Bar Graphs

Due: Tuesday 3/6 by 11:59pm

Objectives

More practice with nested while loops.

Assignment


This assignment is a continuation of Classwork 8. (Note: you must still submit Classwork 8 and Homework 5 separately.) For this homework assignment, embellish your program for Classwork 8 with the following features:

  1. Since bar graphs do not make sense for negative numbers, add another inner while loop to your program that keeps pestering the user until he enters a number strictly greater than zero.

  2. After the outer while loop terminates, print out the largest number entered by the user.

  3. After the outer while loop terminates, print out the average number entered by the user.

A sample run of your program might look like:



PT[203]% gcc bar2.c

PT[204]% ./a.out
Enter a positive number (type 'quit' to end) 30
******************************
Enter a positive number (type 'quit' to end) 29
*****************************
Enter a positive number (type 'quit' to end) 17
*****************
Enter a positive number (type 'quit' to end) 28
****************************
Enter a positive number (type 'quit' to end) 50
**************************************************
Enter a positive number (type 'quit' to end) 67
*******************************************************************
Enter a positive number (type 'quit' to end) 36
************************************
Enter a positive number (type 'quit' to end) 19
*******************
Enter a positive number (type 'quit' to end) 17
*****************
Enter a positive number (type 'quit' to end) quit
Sum = 293, count = 9
Largest number found = 67
Average number found = 32.5556
PT[205]% 

PT[205]% ./a.out
Enter a positive number (type 'quit' to end) -2
*** -2 is not positive, re-enter. ***
Enter a positive number (type 'quit' to end) 12
************
Enter a positive number (type 'quit' to end) 14
**************
Enter a positive number (type 'quit' to end) 9
*********
Enter a positive number (type 'quit' to end) 0
*** 0 is not positive, re-enter. ***
Enter a positive number (type 'quit' to end) -2
*** -2 is not positive, re-enter. ***
Enter a positive number (type 'quit' to end) 8
********
Enter a positive number (type 'quit' to end) quit
Sum = 43, count = 4
Largest number found = 14
Average number found = 10.75
PT[206]% 

Notes

What to submit

Use the script command to record yourself compiling your program and running your program 3 times using different numbers. Use exit to terminate the recording. Only record yourself compiling and running your program. DO NOT record yourself editing your program. If you mistakenly start up nano while running script, just exit from script and start over. (The new typescript file will overwrite the old one.)

When you are done. Use:


cat typescript

to check the contents of your typescript file. Make sure it does not include you editing your program. Then submit your program and typescript file:


submit cs104_chang hw05 bar2.c typescript