# If statement hanging...

This is a discussion on If statement hanging... within the C Programming forums, part of the General Programming Boards category; I am trying to check for valid date.. if it is not valid then I ask them to reenter the ...

1. ## If statement hanging...

I am trying to check for valid date.. if it is not valid then I ask them to reenter the date. Otherwise it should ask for the deposit. But when I enter a bad date and then reenter the date it hangs? Why?

Code:
```case 1:
printf("Please enter a valid date from 1 to 31:  ");
scanf("%d", &date);
if ((date < 1) || (date > 31)){
printf("Please enter a valid date from 1 to 31.  ");
scanf("%d", &date);
}else
printf("How much do you want to deposit?   ");
scanf("%f", &dpst);
if ( crdt == 0 ) {
blnce = strt_blnce + dpst;
} else if (crdt > 0)
blnce = blnce2 + dpst;
printf("Your current balance is \$%1.2f. \n\n", blnce);
crdt++;
scanf("%d", &opt);
break;```

2. Your missing a } to close the else. The scanf for the amount is executing...so its "hanging" waiting for input

3. there is no opening or closing brace to the else statement

4. Code:
```case 1:
printf("Please enter a valid date from 1 to 31:  ");
scanf("%d", &date);
if ((date < 1) || (date > 31))
{
printf("Please enter a valid date from 1 to 31.  ");
scanf("%d", &date);
//Missing braces in red
} else {
printf("How much do you want to deposit?   ");
scanf("%f", &dpst);
}
if ( crdt == 0 ) {
blnce = strt_blnce + dpst;
}
else if (crdt > 0)
blnce = blnce2 + dpst;
printf("Your current balance is \$%1.2f. \n\n", blnce);
crdt++;
scanf("%d", &opt);
break;```
I suppose to need a closing brace you need an open one too

5. See, this is why people don't like K&R.

*ducks*

6. K&R

7. '...We follow the style use in the book The C Programming Language...Pick one style, preferably ours, use it consistently, and don't waste time arguing.'

The Practice of Programming by Brian W. Kernighan & Rob Pike
::evil laugh::

~/

8. omg i cant believe they put that in a book

9. I'm glad I missed that book.

10. You people apparently have no sense of humor.

Quzah.