Classwork 8: Bar Graphs

Objectives

To practice using nested while loops.

The Assignment

For this assignment, you will write a program that prints out a horizontal "bar graph" using numbers entered by the user.


PT[225]% gcc -Wall bar.c

PT[226]% ./a.out
Enter a positive number (type 'quit' to end): 3
***
Enter a positive number (type 'quit' to end): 17
*****************
Enter a positive number (type 'quit' to end): 23
***********************
Enter a positive number (type 'quit' to end): 22
**********************
Enter a positive number (type 'quit' to end): 9
*********
Enter a positive number (type 'quit' to end): 4
****
Enter a positive number (type 'quit' to end): quit
PT[227]% 

PT[227]% ./a.out
Enter a positive number (type 'quit' to end): quit
No numbers were entered
PT[228]%

The "bars" in this bar graph are the asterisks (*) printed after each user entry. The number of asterisks must be equal to the number entered by the user.

Notes

What to submit

Use the script command to record yourself compiling and running your program several times with different numbers. (Do not record yourself editing your program!) Exit from script. Submit your program and the typescript file:


submit cs104_chang cw08 bar.c typescript