Answered step by step
Verified Expert Solution
Question
1 Approved Answer
need help with this code ASAP! please help! 5.8 Lab 33: Pyramid Using Nested FOR Loops Build a pyramid made up of asterisks. Allow the
need help with this code ASAP! please help!
5.8 Lab 33: Pyramid Using Nested FOR Loops Build a pyramid made up of asterisks. Allow the user to determine the number of rows. Do not accept a number of rows value less than 1 or greater than 25. Use a do-while loop to validate the input. If it is invalid, just read in another value for the number of rows. After you have obtained a valid value for the number of rows, use nested for-loops in your program to build your pyramid Use your outside loop to keep up with the row counter and to calculate the number of leading spaces to be output. Use your inside loop to calculate the number of asterisks needed for the row and output the asterisks. Assume the user has entered a 5. Then your program will need to build a pyramid made up of 5 rows. Use the following table to help you determine the number of leading spaces and trailing asterisks your program will need to output on each row. Notice that the number of leading spaces needs to decrease by one for each row and the number of trailing spaces needs to increase by two for each row Actual Row Number of Single Number Leading Spaces Asterisk Number of Extra Asterisks Output 1 4 1 0 - 2. 3 2. 1 3 2 1 4 4. 1 1 6 ***** ***** 5 1 0 Hints: 1. Use a do-while to validate your numrows value. AFTER you have a valid number stored in numRows, use the value in a for-loop to determine the number of times the loop will repeat. This value will also control the number of rows in your pyramid. 2. Each iteration of your outside for-loop should output the leading spaces followed by a single asterisk (use setw()). 3. If numrows contains the number of rows in the pyramid and rowcounter is used as the row counter in your outside for-loop, then each row has (numrows - rowCounter) leading spaces before the first asterisk. Therefore, your argument to setw() can be (numRows nowCounter + 1) 4. The inside for-loop should print the remaining asterisks in the row. 5. Each row consists of (rowcounter + 2 - 2) trailing asterisks. The body of your inside for-loop should output a single asterisk. The number of times a single asterisk is output should be controlled by the number of iterations of the inside for-loop. For example, the following code could be used as an inside for-loop to output trailing asterisks: for (int j = 1; i
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