所以我一直在制作这个程序一段时间.我已经浏览了整个互联网,但我找不到任何解决方案.每当我在arr [i] .question和arr [i] .answer中输入我的输入时,它说我的问题是错的,而我没有回答这个问题.我尝试过使用cin.ignore(),cin.clear()和cin.sync().我可能一直在错误的地方使用它们,但我不确定.我可能会感到困惑,所以只需查看代码即可.
这是输入格式.
cin >> count;
cin.ignore();
for(int i =0; i < count; i++){
cout << "Enter the question.\n" << endl;
//enter the question
getline(cin, arr[i].question);
cin.ignore();
cout << "Enter the answer.\n" << endl;
//enter the answer
getline (cin, arr[i].answer);
cin.ignore();
}
Run Code Online (Sandbox Code Playgroud)
这是输出格式来测验你.
for(int j =0; j < count; j++){
cout << "\n" << arr[j].question << endl;
getline(cin, userguess);
if(arr[j].answer.compare(userguess) !=0){
cout << "Wrong. Keep trying!\n";
incorrect++;
total++;
}
if(arr[j].answer.compare(userguess) ==0){
cout << "Nice job. Keep it …Run Code Online (Sandbox Code Playgroud)