【发布时间】:2026-02-04 21:45:01
【问题描述】:
嘿,这都是我的代码
void Student::studentMenu() {
int choiceInput;
const string ErrorMsg;
cout << "-------------Student Menu--------------" << endl;
cout << "(1)Start Quiz" << endl;
cout << "(2)View History Score Table" << endl;
cout << "(0)Exit" << endl;
cout << "Option: " << endl;
try {
cin >> choiceInput;
if (choiceInput < 0 || choiceInput>2 || !cin)
{
throw (ErrorMsg);
}
while (choiceInput != 0) {
switch (choiceInput) {
case 1:
generateQuiz();
break;
case 2:
break;
case 0:
break;
}
break;
}
}
catch (string msg)
{
cout << "Please only enter valid integer from 0-3" << endl;
Student::studentMenu();
}
}
基本上,它会检查用户输入,如果输入的非整数大于 3,则抛出异常。显示错误消息后,它应该重定向回学生 menu() 页面。当我输入一个像 5 这样的整数时,输出是预期的,但是当我输入一个 char 'f' 时,它会不断循环错误消息
请帮帮我,谢谢!
【问题讨论】: