刚接触C++的小白求大神指点,为什么我的这段程序总是运行到一半就不动了?

#include <iostream>
#include <string>
using namespace std;
int score;
int cingrade() {
cout << "已输入考生成绩" << score << "分" << endl;
return score;
}
void showgrade() {
cout << "该考生成绩为" << score << endl;
}
void deletegrade() {
score = 0;
cout << "该考生成绩已删除" << endl;
void showgrade(int score);
}
int main() {
int a; string n;
string choice;
char Q;
cout << "菜单选项" << endl;
cout << "A.输入成绩" << endl;
cout << "B.显示成绩" << endl;
cout << "C.删除成绩" << endl;
cout << "请输入学生名字(输入完成按回车)和成绩(输入完成按回车)" << endl;
cin >> n >> a;
cout << "已输入考生"<<n<<"成绩" << a << "分" << endl;
cout << "请输入选项,输入Q退出" << endl;
cin >> choice;
while (choice != "Q") {
if (choice == "A") {
cin >> a>>n;
cout<<cingrade();
break;
}

else if (choice == "B") {
cin >> a >> n;
showgrade();
break;
}

else if (choice == "C") {
cin >> a >> n;
deletegrade();
break;
}
cout << "请输入选项,输入Q退出" << endl;
cin >> choice;
}
return 0;
}

问题比较多,比如这一段:
if (choice == "A") {
cin >> a >> n;
cout << cingrade();
break;
}
这里cingrade用于显示score,但score事先没有赋值,像这样的错误底下还有好几个。自己好好地把代码从头到尾过一遍,虽然会有些头痛,但有利于提高你的“神识”
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答