I've been trying to do the less comfortable version of mario.c for a while, here is what I've been able to put together so far:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// declare height variable for scope purposes
int height;
// do while loop ensures code is run atleast once
do
{
height = get_int("Enter the height of your pyramid: ");
}
// if height is less than 0 or greater than 23 the user will be prompted for input again
while (height < 0 || height > 23);
// for every row
for (int row = 0; row < height; row++)
{
// print the amount of spaces
for (int spaces = row; spaces < height - 1; spaces++)
{
printf(" ");
}
// print out the hashes
for (int hashes = row; hashes < height + 1; hashes++)
{
printf("#");
}
printf("\n");
}
} Everything was looking good until I got to the hashes. Right now, my pyramid is printing the correct number of spaces and hashes but the hashes are printed upside down. So if your input was 5, the pyramid would look like this:
######
#####
####
###
##
The hashes are arranged upside down. (The upper two hashes are printed at the bottom, etc.) but the whitespace is just fine. Can anyone tell me what I am doing wrong?