Question: Write a program that prints an hour glass using the character *. The user will enter the number of '*'s on the top row and

 Write a program that prints an hour glass using the character

*". The user will enter the number of '*'s on the top

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: 1. Program hourglass.cpp using the starter template provided: (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 First, test your code on a top row size of 3 '*'s and one row. Your program should display only one total row. Second, test your code on a top row size of 4 "*'s and two rows. Continue testing your code for larger input values and combinations Test your code on invalid input to ensure that only valid values are used when displaying the hour glass

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!