I'm still on my prompt part, couldn't get to the pyramid yet, my code compiles but I can't make the loop recursive, that is, after the first entry it goes back to the prompt $. Here is the code:

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

int main(void)
    int n;
        n = get_int("Height: "); 
    while (n < 0 && n > 8); 
    printf("Height: \n");

Thank you for your help.

3 Answers 3


Do you know how you would confirm that the variable was stored? i.e. in response to the question "confirming (for yourself) that you’ve indeed stored the user’s input successfully?"

$ ./mario Height: -1 Height: 0 Height: 42 Height: 50 Height: 4 Stored: 4

  • Thank you very much. I'll do that.
    – 333PPP
    Aug 23, 2020 at 14:12

First of all, "recursive" means something that calls itself repeatedly. You mean that you can't get the loop to repeat.

Think about the condition clause. while (n < 0 && n > 8); When can any number be less than 0 AND greater than 8 at the same time????? Maybe you meant to use OR instead of AND?


Thank you Cliff B. I'm not a native English speaker, sorry about that. I'll try what you're telling me. Thanks again. Edit: I tried, the mistake was the signs were inverted. I meant to write

(n > 0 && n < 8)

now I can't stop the loop from repeating. Gonna work on that. Still, any help will be welcome.

  • That was the wrong direction to go. You want the loop to repeat when the input is invalid. Your new test repeats the loop when the input is valid. Why don't you just change the && to || as I had originally suggested???
    – Cliff B
    Aug 12, 2020 at 21:38
  • OK I'll do that. Thanks so much. Edit: I did it and it worked. So thanks again.
    – 333PPP
    Aug 12, 2020 at 22:04

You must log in to answer this question.

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