1

The following is my work for mario in pset1 and I do not understand the errors' meaning indicated in point 2.

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

int main (void)

{
//Getting user's input for height

int height;

    do
    {
        printf ("Please enter the height within 1 to 23: ");
        height = GetInt();
    }
    while ( height < 1 || height > 23 );

    //a line consist of space and hash
    for (int line = 0; line < height; line++)
    {
          // print spaces
          for ( int space = height - line; space <= line; space--)
          {
             printf ( " " );
          }

          // print hashes
          for ( int hash = 2; hash <= line + 2; hash++ )
          {
             printf ("#");
          }

          // print new line
              printf ("\n");                               
     }    

}  

The following are the errors feedback from CS50 in which I dont understand. i.e. killed by server? exit code? output? Need your help.....

enter image description here

2 Answers 2

1

There is a flaw in your While condition of your Do-While loop which would address the first error. When check50 says it expects an exit code of 0, that just means it expects the program to successfully terminate. Based on your error code that isn't happening for an input of 0.

Also, your output for height = 1 is incorrect. It's not the "\n", because you need that new line printed to continue building the pyramid line after line.

Remember that the first line is always a special case with regards to the hashes that need to be printed.

Sorry I can't help more, and am being intentionally vague. But you'll appreciate it so much more when you finally find that bug in your code :)

1
  • The assignment is actually asking for a non-negative integer no greater than 23, so while it is working as posted, it's not working within the scope of the problem set. The error messages from check50 are suggesting that with height = 0 the program is prompting for a retry, rather than printing nothing, returning 0, and then terminating. I'll concede that "special case" is a bit of a misnomer, but the point still stands because it always has to print 2 hashes for any positive value entered by the user. May 6, 2015 at 7:58
0

Get rid of your first printf line. Check50 doesn't like that. I know it seems strange to not have a nice message asking for input, but that's what it wants.

It also doesn't like your new line "\n" operator at the end.

3
  • I had this same problem. So, when I got rid of the printf entry prompt, it blows up the rest of my test numbers with "\ expected output, not a prompt for input".
    – Brian T
    Jan 16, 2015 at 16:56
  • Based on new pset specs it appears from the example that the expected first prompt should simply say "height:". As such, you may want to have a prompt for first input
    – lethaljd
    Jan 16, 2015 at 17:20
  • Thank you. I see they did that. I figured out that they want the program to return/end/break when a zero is entered and not prompt again.
    – Brian T
    Jan 16, 2015 at 17:30

You must log in to answer this question.

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