Question: C++ problem Write a program that prints an hour glass using the character '#'. The user will enter the number of '#'s on the top
C++ problem
Write a program that prints an hour glass using the character '#'. The user will enter the number of '#'s on the top row and then the number of rows from the top to the middle row. For instance, an hour glass with 7 '#'s in the top row and with 3 rows from the top row to the middle row looks like:
#######
#####
###
#####
#######
No row is allowed to have less than two '#'s.
(a) Prompt and read in the number of '#'s in the top row.
(b) If the number of '#'s is less than three, print the error message "Size of the top row must be at least three.", and prompt again for the number of '#'s in the top row. Repeat until the user enters a valid number. (Use a while loop.) (c) Prompt and read in the number of rows from the top row to 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 number less than 1 or a number that leads to a row in the hour glass 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 hour glass. Your outer for loop will iterate over the number of rows times. For each row use one nested for loop to display blanks (the top row contains no blanks) and another nested for loop to display the characters '#'.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
