我被卡住了,一切都是正确的,除了等级不会显示,任何帮助都将不胜感激!
#include <iostream>
using namespace std;
void calcScore(int grade, double&total);
int main()
{
//declare variables
int score = 0;
int totalPoints = 0; //accumulator
char grade = ' ';
//get first score
cout << "First score (-1 to stop): ";
cin >> score;
while (score != -1)
{
//update accumulator, then get another score
totalPoints += score;
cout << "Next score (-1 to stop): ";
cin >> score;
} //end while
//display the total points and grade
cout << "Total points earned: " << totalPoints << endl;
cout << "Grade: " << grade << endl;
return 0;
} //end of main function
void calcScore(int grade, double & total)
{
if (total >= 315)
grade = 'A';
else if (total >= 280)
grade = 'B';
else if (total >= 245)
grade = 'C';
else if (total >= 210)
grade = 'D';
else
grade = 'F';
}
答案 0 :(得分:6)
您已将此标记为作业,因此我不会向您展示代码解决方案。有几件事你可以看一下:
calcScore
函数永远不会被调用。grade
传递给calcScore
,因此您将在grade
功能中使用calcScore
的本地副本进行操作。 Is that really what you want? grade
为char
,但在int
声明中声明为calcScore
。你了解两者之间的关系吗?