CS 50- Pset 1 Mario Program
Posted
by
boametaphysica
on Stack Overflow
See other posts from Stack Overflow
or by boametaphysica
Published on 2014-05-30T09:17:14Z
Indexed on
2014/05/30
9:25 UTC
Read the original article
Hit count: 378
the problem set asks us to create a half pyramid using hashes. Here is a link to an image of how it should look-
I get the idea and have written the program until printing the spaces (which I have replaced by "_" just so that I can test the first half of it.
However, when I try to run my program, it doesn't go beyond the do-while loop. In other words, it keeps asking me for the height of the pyramid and does not seem to run the for loop at all. I've tried multiple approaches but this problem seems to persist.
Any help would be appreciated!
Below is my code-
# include <cs50.h>
# include <stdio.h>
int main(void)
{
int height;
do
{
printf("Enter the height of the pyramid: ");
height = GetInt();
}
while (height > 0 || height < 24);
for (int rows = 1; rows <= height, rows++)
{
for (int spaces = height - rows; spaces > 0; spaces--)
{
printf("_");
}
}
return 0;
}
Running this program yields the following output-
Enter the height of the pyramid: 11
Enter the height of the pyramid: 1231
Enter the height of the pyramid: aawfaf
Retry: 12
Enter the height of the pyramid:
© Stack Overflow or respective owner