1

I've got this code for the Mario assignement in pset1. It prints out OK in the shell, but check50 rejects it. Can anybody help me?

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

int main(void)
{
    // initialize variables
    int x, y,z;

    // Request to the user to enter a value
    do
    {
    printf("Please give me an integer between 1 and 23.  ");
    x = GetInt();     
    }
    // check if the value is in range
    while (x <=0 ||x>23);
    y = x -1;
    z = 1;


    for (int i =x; x>0; i--)
    {

        for (int i = 0;i < x;i++)
        {
            // this prints the spaces
            printf(" ");

        }


        for (int i = 1; i <= z; i++)
        {

            //this prints the #
            printf("#");

        }

        // this causes the line break
        printf("\n");

        // adjustment of variables
        x--;
        z++;
    }
    return 0; 
}
0

1 Answer 1

2

When given 3 as input, your program prints out: (I will replace spaces with 0s for simplicity, and # with "hashtag" because stack has some formatting thing with hashes.) 00hastag 0hastaghastag hastaghastaghastag

so

2 spaces, 1 hash
1 space, 2 hashes
no spaces, 3 hashes

Instead, it should be

2 spaces, 2 hashes
1 space, 3 hashes
no spaces, 4 hashes
5
  • I turned printf("\n"); into printf("#\n"); to get one more hash. I do but check50 still rejects it :-( Jul 23, 2015 at 17:52
  • Now you are printing an extra space at the start of each line. Should be pretty easy to fix..
    – i_am_david
    Jul 23, 2015 at 18:30
  • Thanks, that was it :-) Jul 23, 2015 at 19:20
  • If my answer helped, could you please accept it?
    – i_am_david
    Jul 23, 2015 at 19:22
  • Sorry, I just did :-) Jul 24, 2015 at 19:45

You must log in to answer this question.

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