OKAY!一切正常。现在虽然,我必须添加一个布尔函数,以验证我的用户输入的成绩是否有效...我不知道如何做到这一点......叹息。我甚至不知道从哪里开始,但我确实设置了一个原型并在底部启动功能......我是否必须将它包含在main中?如果是这样,在哪里?
我的教授在春假期间认真地向我们扔了太多...无论如何,我必须创建一个布尔函数来检查用户输入的值是否为0-100,但我根本不知道如何做到这一点,我的程序已经非常复杂,因为它是...无论如何,这里是代码,布尔函数在底部,我只声明原型,因为我不知道我的下一个是什么步骤将是。任何帮助将不胜感激。
SOUNDEFFECT.TRACK_PLAY_randomInt
答案 0 :(得分:1)
我没有编译,但这很关键:
if (choice == 4)
代替while()
int menu()
需要return
某事这是你的main()
作为FirstStep;)case 2
只会显示初始值零。并查看我之前的整个编译注释,然后它将起作用。
int main()
{
float asgnment = 0, asgnment1 = 0, asgnment2 = 0, asgnment3 = 0,
asgnment4 = 0, labtest = 0, labtest1 = 0, labtest2 = 0,
labtest3 = 0, lecturetest = 0, lecturetest1 = 0, lecturetest2 = 0,
lecturetest3 = 0, lecturetest4 = 0, postlab = 0, p1 = 0, p2 = 0, p3 = 0, p4 = 0,
p5 = 0, p6 = 0, p7 = 0, p8 = 0, p9 = 0, quiz = 0, quiz1 = 0, quiz2 = 0, quiz3 = 0, quiz4 = 0, quiz5 = 0,
quiz6 = 0, quiz7 = 0, quiz8 = 0, quiz9 = 0, clicker = 0, clickergrade = 0;
int choice;
choice = menu(); // let menu() return the entered int
switch(choice)
{
case 1:
AssignmentGrade(asgnment, asgnment1, asgnment2, asgnment3, asgnment4);
LabTestGrade(labtest, labtest1, labtest2, labtest3);
LectureTestGrade(lecturetest, lecturetest1, lecturetest2, lecturetest3, lecturetest4);
PostLabGrade(postlab, p1, p2, p3, p4, p5, p6, p7, p8, p9);
QuizGrade(quiz, quiz1, quiz2, quiz3, quiz4, quiz5, quiz6, quiz7, quiz8, quiz9);
ClickerGrade(clickergrade, clicker); break;
case 2:
DisplayGrades(asgnment, labtest, lecturetest, postlab, quiz, clickergrade);
}
return 0;
}
答案 1 :(得分:0)
你需要在循环中执行它,如下所示:
int main()
{
int choice;
while(1)
{
choice = menu();
if (choice == 4) break;
your_code_with_switch_here;
}
return 0;
}
当用户输入4时,循环停止if (choice == 4) break;
。否则循环继续。
感谢@FirstStep您的菜单程序效果不佳。它必须像这样重写(返回值):
int menu()
{
int choice;
cout << "Please select an option below." << endl << endl;
cout << "1. Enter Grades" << endl;
cout << "2. Display Grades" << endl;
cout << "3. Show Overall Grade" << endl;
cout << "4. Exit the Program"<< endl; // Will quit the program by using a while statement
cout << "Enter your choice... ";
cin >> choice;
return choice;
}