I am really struggling with mario.c from pset1. I am total novice to programming and so my question might be answered in some of the previous questions but I have not understood them.
My code gives me a pyramid that looks OK, and is OK for most of the rows, but when i do check 50, on rows 1 and 2, it looks like the pyramid should not be so close to the text of the prompt.
here is my code
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int height;
do
{printf ("How high do you want mario to jump? Please choose a number between 1 and 23 ");
height=GetInt ();}
while (height < 0 || height > 23);
for (int rows = 1; rows <= height; rows ++)
{
for (int spaces = 1; spaces <= (23-rows); spaces ++)
{printf (" ");}
for (int hashes = 1; hashes <= (rows+1); hashes ++)
{printf ("#");}
{printf ("\n");}
}
}
and here is the error link: https://sandbox.cs50.net/checks/20242e1dd44f408da3ced0faf1f05a06
I know that there is something funny going on as all the hints I have looked at don't have their space conditions looking like this. I get the rows bit, I get the hashes bit, it is just the spaces. I don't understand how to possibly interpret the for condition when it involves having the spaces decrease with the spaces-- being used.
I have actually got it to work by modifying a loop I found in another of the answers,
for (int row = 0; row <=height; row++)
{
for (int spaces = height; spaces - 1 > row; spaces--)
{
printf(" ");
}
for (int hashes = 0; hashes < row + 2; hashes++)
but I don't want to use it - I want to know why mine is wrong and what the more conventional ways of going about it are actually saying. I know this starts at 0 whereas mine starts at 1.
Sorry this is so long and hope someone can help
Many thanks