Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I'm having trouble using only for loops. I would appreciate a full program to see how everything works. Thank you so much! write a program
I'm having trouble using only for loops. I would appreciate a full program to see how everything works. Thank you so much!
write a program that prompts for a number of rows (nRows) from the user, and prints an hourglass of either nRows or nRows-1 rows. Your should only print hourglasses of 3 to 25 rows (to let the shape fit on a single screen), so force the user to enter a reasonable number of rows. Print different error messages if nRows is too big or too small. Then, if nRows is even, add one to get an odd number of rows. The first and last rows of the hourglass must abut the left margin. You may only print single character spaces or stars T. and newline An flush or endl. You may not M use any output manipulators, e.g., setw in this program. For example, if user enters 9 for number of rows, the hourglass will have g stars on the first line, 7on the second, 5 on the third, 3 on the fourth, then 1, 3, 5, 7,9 stars on the rest of the lines.You may use For Nested Loop sto print the shape itself. For example, you could have a nested For Loop structure that writes the top (inverted triangle of stars, then a second nested For- Loop structure that write the bottom triangle of stars.l don't want any if statements used. Do this all with For loops.You will have a fourth outer loop to force user entry to be reasonable. You MUST do the number-of-spaces and number-ofstars calculations for each row based ONLY on the total number of rows and the current row number. You MAY NOT use the previous line's number of spaces er stars for these caleulations. mple (with user entries shown in bold italic): of rows Enter That is to few rows for me to make an hourglass 30 Enter number of rows ourglass That is too many rows for me make an Enter number of rows 4 ce this becomes 5 rowsStep 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