Hello! So I'm currently trying to teach myself C via the Internet, and I'm stuck on the While loop. Here's what I'm trying to do: the user should input a non-negative number no greater than 23; if the number is greater than 23, then the prompt should let the user try again and then re-evaluate the new number to see if it's a non-negative number.
Here's what I have:
However, when I run the program and type in 28 for example, it's an infinite loop and does NOT ask for another integer (no GetInt(); activated), which I don't understand because in my while loop, I state that the prompt should allow the user to type in another number and then evaluate to see if it should get out of the while loop.Code:#include <cs50.h> #include <stdio.h> int main(void) { printf("Insert a non-negative integer no greater than 23: "); int x = GetInt(); while (x > 23) printf("Insert a non-negative integer LESS than 24!: "); x = GetInt(); while (x < 0) printf("Insert a NON-NEGATIVE integer less than 24!: "); x = GetInt(); return 0; }
What am I doing wrong? Thank you!