>> ROB BOWDEN: Hi, I'm Rob, and let's jump into the hacker edition of Mario.
So first thing we need to do is get the height from the user.
Here we're asking them for a non-negative integer less than 24 and
we're using the CS50 GetInt function to grab that integer from the user.
We see we're inside of a do-while loop that will continue looping as long as
height is greater than 23 or less than 0.
And so we'll continue until the user actually gives us what we want.
>> Once we have that height, we get to the main for loop of our program.
So let's first look at an example from the pset spec.
We see in this example that when we enter a height of 4, the bottom row
first prints four hashes, two spaces, and four more hashes.
>> Then one row above that prints one space three hashes, two spaces to
separate the pyramids, and then three more hashes.
And above that, two spaces, two hashes, two spaces, two hashes.
And finally, three spaces one hash, two spaces one hash.
So you should start to notice the pattern here.
>> Let's look at the code for how we're going to do that.
We see here that we're iterating over all rows of the pyramid.
First we want to calculate the number of spaces.
And remember that we have to start at the top of the pyramid and work our
way down since we can't print the bottom then one row up and
then one row up.
So at the top of the pyramid, notice that the number of spaces is equal to
height minus 1.
We're going to print three spaces then one hash and then two spaces to
separate and another hash.
>> So spaces is equal to height minus row.
If the row is 1 and our height is 4, that'll give us 3 spaces, as we want.
Then this for loop just prints that number of spaces.
If spaces is three, then we're going to create a single space three times.
>> Continuing, now we want to print the hashes of the left pyramid, which is
just equal to the row number.
Looking back here, in row one, we print one hash.
In row two we print two, in row three we print three.
So we simply loop row times printing hash symbol.
Then for all rows of the pyramid, we print exactly two spaces to separate
those pyramids.
>> And finally, we want to print the right side of the pyramid, which is
again the same number of hashes as the left side.
And so it's the same exact for loop as above here.
Finally, we need to create a new line in order to move on to the next row of
the pyramid and continue printing.
And that's it.
My name is Rob and this was Mario.