Where did I go wrong with this code for my do while loop?
Code:
int main()
{
char response;
do
{
/* My main code would be here */
printf("\n\n\nDo you wish to convert another number? (y) or (n): ");
scanf("%c", &response);
while(!(response == 'y' || response == 'Y' || response == 'n' || response == 'N'))
{
printf("\nPlease enter (y) or (n): ");
scanf("%c", &response);
}
} while(response == 'y' || response == 'Y');
return 0;
}
The output when the program goes to the do while loop is:
Code:
Do you wish to convert another number? (y) or (n):
Please enter (y) or (n):
For some reason that I do not see the program skips the first scanf() and enters the while loop going instead to the second scanf(). What am I doing wrong?
Also does C have and equal to the C++ ignore function? I would normally code the response input as:
Code:
cin >> response;
cin.ignore(100, '\n');
I do not know if C has something similar to this for garbage clean-up.