# Thread: Question with If-then Statements?

1. ## Question with If-then Statements?

I have this written code below and I am doing an If-then statement. For the first If-then, I get it to where it tells me "Try Again" but when I do it again and I enter the same number (just to check to see if it says "Try Again" for a 2nd time), it goes on to the next question. I want it to were if you keep entering the wrong number it keeps saying "Try Again" until you enter the right one.

Code:
```#include <stdio.h>

int main(void)
{
int hour, spots, parking_permits;
float time;

printf ("What hour are you looking for parking? \n");
scanf ("%d", &hour);
if (hour<0 || hour>23)
{
printf ("Invalid. Try Again. Time must be between 0 - 23 \n", hour);
}

printf ("How many spots are available this semester? \n");
scanf ("%d", &spots);

printf ("How many parking permits were given this semester? \n");
scanf ("%d", &parking_permits);

time = ( 12 - abs(12 - hour) )*(parking_permits/spots);
printf ("You will have to wait %.2f minutes to find parking\n", time );

getch ();

return 0;
}```

2. You'll have to use while loop(or do while), in order to keep it saying the error. Something like this:
Code:
```do
{
printf ("What hour are you looking for parking? \n");
scanf ("%d", &hour);
if (hour<0 || hour>23)
printf ("Invalid. Try Again. Time must be between 0 - 23 \n", hour);
else
break;
}while(1);```