At the end of getData() you need to add code to remove the '\n' from the keyboard buffer. Getting numbers (ints, floats, doubles) has the side affect of cin leaving the Enter key '\n' in the keyboard buffer, so the next time a character string needs to be entered cin appears not to do anything. Narue wrote a very good article about how to flush the input stream in
this link.
>>Also, how can I prevent input of characters other than numbers in integers, float etc?
You have to accept them as strings and parse the characters to see if there are any non-numeric digits.
Another method is to call cin.peek() to see if there is anything in the keyboard except '\n'.
int x;
cout << "Enter a number ... ";
cin >> x;
if(cin.peek() != '\n')
cout << "bad data\n";
Last edited by Ancient Dragon; Apr 29th, 2008 at 10:40 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Offline 21,953 posts
since Aug 2005