Where did I go wrong with this code for my do while loop?
The output when the program goes to the do while loop is: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; }
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?Code:Do you wish to convert another number? (y) or (n): Please enter (y) or (n):
Also does C have and equal to the C++ ignore function? I would normally code the response input as:
I do not know if C has something similar to this for garbage clean-up.Code:cin >> response; cin.ignore(100, '\n');



LinkBack URL
About LinkBacks


