Quick IF statement question (beginner)
Hi there, I am new to C and I having trouble with this if statement which is called by the main function when the user requests to quit:
Code:
exitfunction()
{
char exitquestion[1]; /* Local variable for storing question response about quitting. */
printf("\n\nAre You Sure You Wish To Quit? [Y]es Or [N]o: ");
scanf("%c", &exitquestion);
if (exitquestion[0] == 'Y' || exitquestion[0] == 'y') { exit(0); } /* Returns exit code 0 to OS */
else {
if (exitquestion[0] == 'N' || exitquestion[0] == 'n') { main(); } /* Back to start. */
else {printf("\n\nOnly [Y]es Or [N]o are acceptable inputs!"); exitfunction(); } /* If user enters neither 'Y' or 'N' then go back and ask again. */
}
}
The problem is, when the function is called, it prints the 'Are you sure you wish to quit?' question immediately followed by the error 'Only Y or N are acceptable inputs' message, without prompting for a input. Thus is does what is meant to do in that situation and loops back to the top, this time it asks for the neccessary input. I am completly stumped by this, as surely it should pause for input every time the function is run.
So, any suggestions (oh and please keep it simple for me to understand!)?
Cheers.