Can I make cin.ignore() flush the keyboard buffer

Hello,

I am writing a homework program and I need some help.

I think I am having trouble with the keyboard buffer, unless you educate me and tell me otherwise. Here is what is happening:

I have:
1
2
3
4
5
6
7
8
9
10
11
//Constants Used:
const int iLength = 21;                 //20 Chars + 1 null terminator.


//Variable Declaration Section:
int iCounter;                           //Simple Integer counter.
//3 char. variables to hold 3 user input.
char cRunner1[iLength], cRunner2[iLength], cRunner3[iLength];
double dFinish1, dFinish2, dFinish3;    //3 variables to hold 3 user inputs.
char cExtraName[iLength];               //1 extra name to help in the sorting.
double dExtraNum;                       //1 extra variable to help in sorting. 

Then I have:
1
2
3
4
5
6
7
8
9
10
//Accept the name of the runner 1.
cout << "Name of Runner number 1: ";
cin.getline(cRunner1, iLength);

//Ignore anything left in the keyboard buffer.
cin.ignore();

cout << "Reminder: finishing times must be greater than zero.\n";
cout << "Finish Time for Runner number 1: ";
cin >> fixed >> showpoint >> setprecision(2) >> dFinish1;

OK if I enter a name less that 20 characters long, the program hangs and does not produce the request for the finishing time?

I need to enter names as long as 20 characters, but it only accepts 20 characters or it hangs?

Any ideas?

Thanks

Wassim
Topic archived. No new replies allowed.