Question
(C Language) Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a
(C Language) Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...".
The program will ask the user to enter a non-zero positive number. Using a while loop, validate that the number is not greater than 40, and if so, re-ask for the number. Put the entire program into a sentinel-controlled loop so that the user can enter either zero (0) or a negative number to end the program.
Create constants for 1 (the minimum number for the histogram), and 40 (the maximum number for the histogram), and use these constants in the prompts, the validation condition and error message, and the sentinel-controlled loop and the histogram loop.
Hints:
- Validation messages are indented 3 spaces
- You can use either a pre-test loop (with the initial prompt outside the loop, and the re-prompt at the end of the loop) or a post-test loop (with the prompt inside the loop, and a decision to print the histogram also inside to loop).
- Coded the histogram using a for loop (although any type of loop could be used)
Example Run:
(bold type is what is entered by the user)
Enter a non-zero positive number less than 40: 5 ***** 5
Enter another non-zero positive number less than 40: 48 The number entered was greater than 40. Please re-enter: 8 ******** 8
Enter another non-zero positive number less than 40: -1
Bye...
The example run shows EXACTLY how your program input and output will look.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started