This is as far as I've gotten with Itsa Mario. I've got the first part of the problem down just fine, but I'm extremely tripped up by the second part. I'm very curious because I know that the spaces before the hashes should be (height - 1), but when I put that instead of ++s I get an endless loop of nothing until I close out the terminal. I don't understand why that is, so I put ++s in there to keep that from happening. If someone could explain how I'm getting the endless loop when doing so I would appreciate that.
#
#
#
#
#
#
This is what comes out currently. I've got x number of hashes high now, but I cannot figure out how to program the certain number of spaces and the certain number of hashes. I believe I can start i at 1 and then hashes would equal i + 1 in a loop? I'm so confused at this point. I've been on this second half of Mario for five days now after figuring out the water problem and the first half on my own on the first night of working this pset. This second half of the problem feels like such a jump but I feel as though once I figure out how to do it I'll wonder how it ever took me 10+ hours to figure out!
I'm not looking for an answer (which is why I warily read many other Mario answers but not all of them because I don't want to know how to code it), I am just extremely perplexed at this point. I've spent around two hours a day on this since Saturday night and I'm struggling a lot. It's not because I'm stupid, right? This is my first experience with programming and I'm finding it very challenging. I enjoy the challenge but at this point I'm now running blindly into walls with no idea of where to go from here. I'm randomly plugging in integers and I don't like coding that way because I'm not learning, it's just an ugly version of guess and check.
I've read through this (Stuck on pyramid for mario.c) answer a few times but I'm still lost on how to print the spaces and hashes. That doesn't mean I'm not cut out for programming, does it? I'm sorry if this is extremely similar to everyone else's Mario question but hopefully someone will be able to guide me in the right direction without answering the question for me.
CODE IS BELOW.
Spaced out so I don't spoil anyone else's pset experience.
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int height;
//Select the height of Mario's pyramid.
do
{
printf("Choose a number up to 23:\n");
scanf("%i", &height);
}
while(height < 0 || height > 23);
//Pyramid loop.
char hash = '#';
int h = 0;
char space = ' ';
int s = 0;
int i = 0;
for(i = 1; i <= height; ++i)
{
for(s = height - 1; s <= height; ++s)
{
printf("%c", space);
}
for(h = i + 1; h <= height; h = ++i)
{
printf("%c", hash);
printf("\n");
}
}
return 0;
}