CS 200 - Lab 9

Bar Graph

Write a program that prompts the user to draw one or more bars of a bar graph.

To draw each bar, the program should prompt the user for a length, and then draw a that many equals ("=") characters.  After drawing each bar, the program should ask whether or not to continue, and read a single input character.  If the user enters a 'Y' or 'y' character, then the program should continue.  If the user enters any other character, the program should finish.

Example of running the program (user input in bold red):

length? 20
another? y
length? 65
another? Y
length? 51
another? n

Getting Started

If you have a solution open in Visual Studio, close it (File->Close Solution).

Download lab9.zip.  Import it into Visual Studio (File->Import...).

Add your code to the source file called BarGraph.c.


You will need nested loops.  The outer loop will have the code to prompt for and draw a single bar.  The inner loop will draw each character in a single bar.

For each loop, you will need to choose between a while and a do/while loop.  The rule is that if the loop should be able to execute 0 times, it should be a while.  If it must be guaranteed to execute at least once, it should be a do/while.

You should start with a program that prompts for and draws a single bar.  That code will then become the body of the outer loop that draws however many bars the user requests.