1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
#include <iomanip>
using namespace std;
void getScore(double &score);
void calcAvg(double score1, double score2, double score3, double score4, double score5, double lowest);
double findLowest(double score1, double score2, double score3, double score4, double score5);
void isValid();
int main()
{
double score1, score2, score3, score4, score5, lowest;
getScore(score1);
getScore(score2);
getScore(score3);
getScore(score4);
getScore(score5);
lowest = findLowest(score1, score2, score3, score4, score5);
calcAvg(score1, score2, score3, score4, score5, lowest);
return 0;
}
void getScore(double &score)
{
isValid();
}
void calcAvg(double score1, double score2, double score3, double score4, double score5, double lowest){
lowest = findLowest(score1, score2, score3, score4, score5);
double avgScore = (((float)score1 + score2 + score3 + score4 + score5) - lowest) / 4.0;
cout << setw(4);
cout << fixed << showpoint << setprecision(2);
cout << "The average of the 4 highest scores is " << avgScore << endl;
}
double findLowest(double score1, double score2, double score3, double score4, double score5)
{
double lowest = score1;
if (score2 < lowest) {
lowest = score2;
} else if (score3 < lowest) {
lowest = score3;
} else if (score4 < lowest) {
lowest = score4;
} else if (score5 < lowest)
lowest = score5;
return lowest;
}
void isValid() {
double score;
cout << "Enter test score: ";
cin >> score;
while (score < 1 || score > 100) {
cout << "Please enter a score between 0-100:";
cin >> score;
}
}
|