0

When I execute check50 it says I have some errors in my code.

:) mario.c exists
:) mario.c compiles
:) rejects a height of -1
:) handles a height of 0 correctly
:( handles a height of 1 correctly
\ expected output, but not " ##\n"
:( handles a height of 2 correctly
\ expected output, but not "  ##\n ###\n"
:( handles a height of 23 correctly
\ expected output, but not "##\n..."
:( rejects a height of 24
\ expected output, but not "##\n..."
:) rejects a non-numeric height of "foo"
:) rejects a non-numeric height of ""
https://sandbox.cs50.net/checks/8df543c9db0747abbb99205cd0d1440f 

However when I execute ./mario it comes up with the desired result. For example,

username@ide50:~/workspace/pset1 $ ./mario
Height: 1
 ##
username@ide50:~/workspace/pset1 $ ./mario
Height: 2
  ##
 ###
username@ide50:~/workspace/pset1 $ ./mario
Height: 23
                       ##
                      ###
                     ####
                    #####
                   ######
                  #######
                 ########
                #########
               ##########
              ###########
             ############
            #############
           ##############
          ###############
         ################
        #################
       ##################
      ###################
     ####################
    #####################
   ######################
  #######################
 ########################
username@ide50:~/workspace/pset1 $ ./mario
Height: 24
Height: 3     

The code that I executed is:

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

 int main(void)
{
  int r, j, n, i;
do
{
    printf("Height: ");
    i = GetInt( );
}
while (i < 0 || i > 23);

for (r = 0; r < i; r++)
{
  for (j = 0; j <= ((i+1) - (r+2))  ; j++)
  {
      printf(" ");
  }
  for (n = 0; n < r+2; n++)
  {
      printf("#");
  }
  printf("\n");  
}
}

I'm not sure how to fix the errors.

0

It looks like something is off with how your code prints hashes: you seem to have some empty space to the left of the lowest row of "##", even when your height is 1 (the lower left corner of your half pyramid should be touching the edge of your console). Note what check50 was NOT expecting to find (between quotation marks) in the first couple of errors. If this still does not help, perhaps you can share your code to figure out what is going wrong? Thanks!

You must log in to answer this question.

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