對於我的C++任務,我必須從一組三個測試分數中找到最低,最高和平均測試分數。如果在C++中找到最高和最低的測試分數,兩個或全部三個測試分數是否相同?這裏是我迄今爲止運行的代碼,除非兩個分數相同。如何從3個考試分數中找出最低分和最高分時考慮考試分數中的關係?
#include <iostream>
using namespace std;
int main()
{
int _midtermgrade, _projectaverage, _homeworkaverage, average;
cout << " Please enter your midterm grade:" << endl;
cin >> _midtermgrade;
cout << "Please enter your project average:" << endl;
cin >> _projectaverage;
cout << " Please enter your homework average:" << endl;
cin >> _homeworkaverage;
if((_midtermgrade >_projectaverage)&&(_midtermgrade >_homeworkaverage)){
cout << "Your highest score is your midterm " << _midtermgrade endl;
}
if ((_projectaverage >_midtermgrade)&(_projectaverage>_homeworkaverage))
cout << "Your highest score is your project " << _projectaverage << endl;
}
if((_homeworkaverage >_projectaverage&(_homeworkaverage>_midtermgrade)){
cout << "Your highest score is your homework "<< _homeworkaverage <<endl;
}
if((_midtermgrade < _projectaverage)&&(_midtermgrade<_homeworkaverage)){
cout << "Your lowest score is your midterm " << _midtermgrade<< endl;
}
if((_projectaverage<_midtermgrade)&&(_projectaverage<_homeworkaverage)){
cout << "Your lowest score is your project "<< _projectaverage<<endl;
}
if ((_homeworkaverage<_projectaverage)&&_midtermgrade)){
cout
<< "Your lowest score is your homework " << _homeworkaverage << endl;
}
average =((_midtermgrade * 20 +_projectaverage* 40 + _homeworkaverage*15)
/(20 + 40 + 15));
cout << "Your currentaverage is " << average <<endl;
if (_midtermgrade < 70){
cout << "You have a failing grade on the midterm." << endl;
}
else
cout << "You have a passing grade on the midterm." << endl;
if (_projectaverage < 70){
cout << "You have a failing grade on the project." << endl;}
else
cout << "You have a passing grade on the project." << endl;
if (_homeworkaverage < 70){
cout << "You have a failing grade on the homework." << endl;
} else
cout << "You have a passing grade on the homework." << endl;
return 0;
}
你可以看看我剛剛發佈的問題謝謝。 – user4954919