hi! can someone help debug my codes?
getline() works properly in my main() but if i'm putting it to another function, it ignores the first getline() w/o entering any words and goes to the 2nd getline.
my program works like this:
i have a menu() that lets the user to choose a category [easy-'e', ave-'a', hard-'h']. for example, if the user chose the letter 'e' it will jump to the easy().
and as soon as i entered the letter 'e', it goes straight to player 2 or the 2nd getline. the easy() consists of two getline (string answers for player 1 and 2)
If i use the simple cin, the program works fine.
how can i fix this?
this is the code segment with the getline() in my easy function..
cout << "\n\nPLAYER 1 Answer: ";
getline (cin, easyAnswerPlayer1); // i declared this as a string. the program ignores this
replace(easyAnswerPlayer1.begin(), easyAnswerPlayer1.end(), ' ', '_');
cout << "PLAYER 2 Answer: ";
getline (cin, easyAnswerPlayer2); // and also this
replace(easyAnswerPlayer2.begin(), easyAnswerPlayer2.end(), ' ', '_');
answerEasy(easyAnswerPlayer1, easyAnswerPlayer2);
and this is the menu ()...
cout << "\nPlease choose a level of difficulty."
"\n[e] Easy \n[a] Average \n[h] Hard \n[q] Quit\n\n"
"Letter: ";
cin >> level;
if (level == 'e')
{
easy();
}
else if (level == 'a')
{
average();
}
else if (level == 'h')
{
hard();
}
thanks!!