Informatics - Deconstructing & Constructing loop functions (week 2)

Hi everyone! Just like I told you in the previous blog, I was assigned to make a triangle shape using loop function. Here, in this blog I will share my journey of modifying the code that my teacher gave to me so that I can make the triangle shape. My final output display should make a triangle by using a 'A' sign. in the first line there will be an 'A' in the middle and it will increase until shaped a triangle.  







I try to modify it by changing some of the things in the code but turns out weird. It doesn't look like triangle, the 'A' sign is increasing but it's going to the right side and not going down. Here's the code and the output: 

I don't really know what is actually going wrong with my code. I decided to modify anything from my previous code and change everything I know. But still the result is not triangle. It is increasing 1 asterisk going down, but the space is not fit.  Here's the code and the result of the code:
Again, I'm trying to modify my code again. This time the output is a lot of 'A' sign and not even make any shape. Here's the code and the output:
I then start to modify the second code again. Then finally I made it. This code succeeds making a triangle shape. Here's the code and the output:
Line 1: includes the input/output stream library, allowing the program to use std::cout for printing to the console.
Line 2: marks the beginning of the main function, where program execution begins.
Line 4: an integer variable rows is declared and initialized to 10. This defines how many rows the equilateral triangle will have. 
Line 6: This is the outer loop that controls how many rows will be printed. i is initialized to 1, representing the first row. The loop runs as long as i <= rows, up to the number of rows specified (in this case, 10). After each iteration, i is incremented by 1 (i++), moving to the next row.
Line 9: This starts another loop that prints spaces. The number of spaces decreases as we go down the rows.
Line 10: This line prints a single space to help center the A's in the triangle.
Line 14: This starts another loop that prints the As. The number of A's increases by 2 for each row.
Line 15: This line prints the character A for each iteration of the loop above.
Line 18: This moves to the next line after printing all the spaces and As for the current row.
Line 20: This indicates that the program has finished running without any errors.

This is the end of this project. I hope you guys like it and maybe some of you can gain some knowledge from this blog. Anyway, thank you for reading my blog and I'll see you guys in the next blog. 

Komentar

Postingan populer dari blog ini

Informatics - Making a Main C++ Program to Run all the Calculator Program (week 11)

Informatics - Triangles (week 18)

Informatics - Making Minimarket Discount Program in C++ version 1 (Week 12)