Следующий код работает не очень хорошо только в первом цикле while, он автоматически дает значение cin, поэтому я не получаю возможность введите его до следующего цикла. Почему это происходит?при использовании getline (cin, string), cin автоматически принимает значение без запроса
char again = 'y';
while (again=='y') {
int n=1 , chance = 5, score = 0, level = 1;
if (n == 1) {
cout << "Game begin!"<<endl;
while (chance) {
cout << "You have " << chance << " chances left." << endl;
cout<<"level "<<level<<" question!"<<endl;
vector<string> actorset = game(graph,level);
int correct = 0;
string s;
cout << "\nyour answer is:";
std::getline(cin, s);
cout << "Your Answer is " << s <<endl;
vector<string>::iterator vit = actorset.begin();
vector<string>::iterator ven = actorset.end();
cout << "Correct Answers are: "<<endl;
for (; vit != ven; vit++) {
if (s.compare(*vit) == 0) {
correct = 1;
}
cout << *vit <<'\t';
}
cout <<'\n';
if (correct == 0) {
chance --;
cout << "Incorrect answer" << endl;
cout << "Your total score is " << score <<"."<<endl;
} else {
score += 10;
level++;
cout <<"Correct answer! You get 10 points!"<<endl;
cout << "Your total score is " << score <<"."<<endl;
}
}
}
cout <<"high score handler"<<endl;
output.open (outfile_name, std::fstream::in | std::fstream::out);
highscore(output,score);
cout << "type y for another try: ";
cin >> again;
}