
Fisher L. answered 03/25/24
Experienced tutor specializing in Java, C++ and Math
For this program, try to think about in terms of what you would do if writing it out by hand. I will explain what I mean using the Step 1 you posted.
For step 1, think about the shape it wants you to make. In this case, it is a rectangle. If you are having trouble thinking about this from a coding perspective, think of it from a math perspective.
Are there any formulas you know for rectangles that could be related to this problem? There are! The most helpful one to think about is the area formula, which is width times height, or a = l * w
This formula just means each row (l) is w units long. So how would you draw this out on a piece of paper?
You would start at the first row and draw out w dots.
Then you move down one row, and draw out w dots again.
You repeat this until you have drawn out all the rows.
Now think of this from a coding perspective.
How do you repeat something? You use loops!
Start with drawing out one row. In this case, you would use the following pseudocode:
for i = 1 until i = w, add 1 to i and print *
Lets call this printRow
Now how can we print multiple rows? Loops again!
for j = 1 until j = l, add 1 to j and do printRow
And that’s all you need for Step 1!
You can use similar logic for step 2 and 3. A hint for step 2 is to think of how a triangle can be drawn using multiple rectangles.