我被指派做一个程序,该程序需要 5 分,降低最低分,然后取最高 4 分的平均值。它不会让我使用变量“最低”。我有点困惑,可以使用一些帮助。
#include <iostream>
#include <iomanip>
using namespace std;
void getValues(float &score1, float &score2, float &score3, float &score4, float &score5);
float findLowest(float score1, float score2, float score3, float score4, float score5, float lowest);
void calcAverage(float score1, float score2, float score3, float score4, float score5, float &lowest);
void displayVales();
int main(void)
{
float score1, score2, score3, score4, score5, lowest;
getValues(score1, score2, score3, score4, score5);
findLowest(score1, score2, score3, score4, score5, lowest);
calcAverage(score1, score2, score3, score4, score5, lowest);
}
void getValues(float &score1, float &score2, float &score3, float &score4, float &score5)
{
cout << "Welcome to the test averaging program!" << endl;
cout << "This program will drop the lowest of five scores." << endl;
cout << "Please enter score #1 --> ";
cin >> score1;
cout << "Please enter score #2 --> ";
cin >> score2;
cout << "Please enter score #3 --> ";
cin >> score3;
cout << "Please enter score #4 --> ";
cin >> score4;
cout << "Please enter score #5 --> ";
cin >> score5;
}
float findLowest(float score1, float score2, float score3, float score4, float score5, float lowest)
{
lowest = score1;
{
if (score2 < lowest) lowest = score2;
if (score3 < lowest) lowest = score3;
if (score4 < lowest) lowest = score4;
if (score5 < lowest) lowest = score5;
cout << "The lowest test score is " << lowest << endl;
}
return lowest;
}
void calcAverage (float score1, float score2, float score3, float score4, float score5, float &lowest)
{ double average;
cout << setw(4);
cout.precision(2);
cout.setf(ios::fixed);
average = (( score1 + score2 + score3 + score4 + score5) - lowest) / 4.0;
cout << "The average of the 4 highest test scores is: " << average << endl;
}