Answered step by step
Verified Expert Solution
Link Copied!

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!

image text in transcribed

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

l Describe what a union is and explain why employees join unions.

Answered: 1 week ago