Why do I have to hit Return an extra time to exit this program?It seems to me that the program stops at cin.get() if there's nothing in the input buffer. Why does it do this?Code://char.cpp #include <iostream> using namespace std; char control(); void main(void) { char ans; ans = control(); cout << ans << endl; cout << cin.get() << endl; } char control() { char c; cout << "Y or N: "; cin.get(c); while (c!= 'Y' && c!= 'N' && c!='y' && c!='n') { cout << "Y or N: "; cin.get(c); cin.ignore(10, '\n'); } cin.ignore(10,'\n'); return (c); }




Reply With Quote