0

Somebody please help me I have watched the walkthrough thrice, many different videos and searched for answers on reddit and stackexchange yet i've been stuck at this for hours now and cant get through. The dots which i will soon replace with spaces are working perfectly but the hashes keep making problems. Where i am right now, i cant print more than one hash in a row. Here is my code and thanks in advance:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    // Prompt user for height
    int Height;
    do
    {
        Height =get_int("Insert Height(between 1 and 8): ");
    }
    while (Height<1 || Height>8);
    
    printf("Stored: %i\n", Height);
    
    // Loop for new line
    for (int line = 0; line < Height; line++)
    {
        // Loop for hash
        for (int hash = 0; hash<= line; hash++)
        {
            // Loop for space
            for (hash = Height - 1; hash > line; hash--)
            {
                printf(".");
            }
        printf("#");
        }
    printf("\n");
    }*
}

Edit: i continued searching after this and came across a comment that said: "remember to keep the loop for spaces before hashes and not inside the loop for hashes" basically meaning this:

// Building the "Mario Hashmid"
#include <stdio.h>
#include <cs50.h>
int main(void)
{
    // Prompt user for height
    int Height;
    do
    {
        Height =get_int("Insert Height(between 1 and 8): ");
    }
    while (Height<1 || Height>8);
    printf("Stored: %i\n", Height);

    // Loop for new line

    for (int line = 0; line < Height; line++)
    {
        //Loop for spaces

        for (int hash = Height - 1; hash > line; hash--)
        {
        printf(".");
        }
        
        //Loop for hashes

        for (int hash = 0; hash <= line; hash++)
        {
        printf("#");
        }
    printf("\n");
    }

AND IT WORKS!!!

  • yay lol!!!!!!!!!! – iliketurtlz Jul 16 at 17:49
  • Great. Can you please answer your own question and accept it? Otherwise, it will stay in the unanswered question pool forever. Also, please remove the working solution from your question and just explain the solution your answer. – Cliff B Jul 21 at 20:40
0

im glad u learnt from ur mistakes

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .