0

How could i fix the exit code of 0 fault? please.

jharvard@appliance (~/Desktop/hacker1): check50 2014.fall.hacker1.mario mario.c
:) mario.c exists
:) mario.c compiles
:( rejects a height of -1
   **\ expected output, not an exit code of 0**
:) handles a height of 0 correctly
:) handles a height of 1 correctly
:) handles a height of 2 correctly
:) handles a height of 23 correctly
:( rejects a height of 24
   **\ expected output, not an exit code of 0**
:) rejects a non-numeric height of "foo"
:) rejects a non-numeric height of ""

[Removed per CS50 policy]

1 Answer 1

1

From the pset: If the user fails to provide a non-negative integer no greater than 23, you should re-prompt for the same again.

Your code does not reprompt, it simply exits. Check50 is looking for the reprompt.

If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)

5
  • Thanks for your reply, not sure how to get the "Retry" result. however I used labeling to go back to start, but this fails to. How could I get a "Retry" result, please. Oct 2, 2015 at 21:38
  • Instead of using the if statement at the top to either proceed or return, you could surround the prompt for input with a do/while loop. The test condition for the while loop would look for invalid input. BTW, 0 is valid input.
    – Cliff B
    Oct 2, 2015 at 21:54
  • "Do/While" loop, seems not to work for me either. if I enter a valid height, it prints for ever, invalid height prints once. Oct 3, 2015 at 17:22
  • Sounds like you are putting the do while loop in the wrong scope. The do while loop should be the condition for getint not for printing the pyramid. So you probably have to move a curly brace from the end of the printing statement to immediately after the getint statement.
    – Evan
    Jul 1, 2016 at 16:43
  • Think about the condition in the while clause. You want it to loop only if the input is invalid, not if it is valid. What was your test condition? I'll bet it was ` while( x>=0 && x <=23) or something very similar.
    – Cliff B
    Jul 1, 2016 at 17:17

You must log in to answer this question.

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