Question
Write a program that prints an oval using the character *. The user will enter the number of *s on the middle row and then
Write a program that prints an oval using the character *. The user will enter the number of *s on the middle row and then the number of rows above and below the middle row. For instance, an oval with 16 *s in the middle row and 2 rows above and below looks like:
************ ************** **************** ************** ************
No row is allowed to have less than two *s. You will write code to check for this.
Prompt and read in the number of *s in the middle row;
(b) If the number of *s is less than three, print the error message Size of the middle row must be at least three., and prompt again for the number of *s in the middle row. Repeat until the user enters a valid number. (Use a while loop.)
(c) Prompt and read in the number of rows above and below the middle row.
(d) If the number of rows is invalid then print Invalid number of rows. and prompt again for the number rows. An invalid number of rows would be a negative number or a number that leads to a row in the oval with less than two *s. Repeat until the user enters a valid number of rows. (Use a while loop.)
(e) Display an empty line.
(f) Use for loops to display the oval. Your outer for loop will iterate over the number of rows times. For each row use one nested for loop to display blanks (the middle row contains no blanks) and another nested for loop to display the characters *.
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