Quote:
Well, each line width is equal to line_height * 2 - 1. And it even works with 1! Although it will break with 0. You cannot have -1 asterisks.
So... with that formula you can now easily create your triangle with just one for loop. The best way is to first store the width in an integer before you enter the loop. Each line will be equal to:
(overall_width - line_width) / 2 in spaces concatenated to,
line_width in asterisks concatenated to,
(overall_width - line_width) / 2 in spaces.
The only other care you will need to have is to either not accept 0 as an input for the height of the triangle or accept it, but output an empty string.
I see the pattern, but I couldn't figure out how to draw the triangle like you said with just one loop. I remembered reading something about strings in my book, and with the pattern you found, I did this. I had to copy a bunch of stuff from the book though, and I'm not sure I really understand how it works...