-2
실행할 때 outstanding
및 unsatisfactory
을 읽지 않습니다. 학년과 모든 것이 잘 작동하는 것 같습니다.어디서 잘못 됐습니까? 프로그램이 "미해결"및 "불만족"변수를 읽지 않습니다
a. 0에서 100까지의 범위의 시험 점수 모음을 읽는 프로그램을 작성하십시오. 프로그램은 각 점수의 범주를 표시해야합니다. 또한 미해결 점수 (90-100), 만족 점수 (60-89) 및 불만족 점수 (0-59)를 세어 표시해야합니다.
b. 실행이 끝날 때 평균 점수를 표시하도록 프로그램을 수정하십시오. 잘못가는 뭐죠
using namespace std;
void displayGrade(int);
int main()
{
const int SENTINEL = -1;
int score, sum = 0, count = 0, outstanding = 0, satisfactory = 0, unsatisfactory =0;
double average;
cout << "Enter scores one at a time as requested." << endl;
cout << "When done, enter " << SENTINEL << " to finish entering scores." << endl;
cout << "Enter the first score: ";
cin >> score;
while (score != SENTINEL)
{
sum += score;
count++;
displayGrade(score);
cout << endl<< "Enter the next score: ";
cin >> score;
if (score >= 90)
outstanding++;
else if (score >=60){
satisfactory++;
if (score >= 0 && score <= 59)
unsatisfactory++;
}
}
cout << endl << endl;
cout << "Number of scores processed is " << count << endl;
cout << "Sum of exam scores is " << sum << endl;
cout << "The number of Outstanding scores is: " << outstanding << endl;
cout << "The number of Satisfactory scores is: " << satisfactory << endl;
cout << "The number of Unsatisfactory scores is: " << unsatisfactory << endl;
if (count > 0)
{
average = sum/count;
cout << "Average score is " << average << endl;
}
system("PAUSE");
return 0;
}
void displayGrade(int score)
{
if (score >= 90)
cout << "Grade is A" << endl;
else if (score >= 80)
cout << "Grade is B" << endl;
else if (score >= 70)
cout << "Grade is C" << endl;
else if (score >= 60)
cout << "Grade is`enter code here` D" << endl;
else
cout << "Grade is F" << endl;
}
답장을 보내 주시면 감사하겠습니다. 내 if 문은 while 루프에만있는 것으로 생각합니다. 그래서 나는 주먹 번호를 입력 할 때마다 그것이 중요하지 않습니다. 'if (score <0 || score> 100)' 'cout << "잘못된 번호 0과 100 사이의 숫자를 입력하십시오. \ n" – user3361763