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 76 77 78 79 80 81
|
#include <iostream>
using namespace std;
void intro();
void getScore(double&);
void calcAverage(double, double, double, double, double);
int findLowest(double, double, double, double, double);
int main()
{
double score1,
score2,
score3,
score4,
score5;
intro();
getScore(score1);
getScore(score2);
getScore(score3);
getScore(score4);
getScore(score5);
calcAverage(score1, score2, score3, score4, score5);
}
void intro()
{
cout << "This program will take five test scores from the user and calculate\n";
cout << "their average after dropping the lowest score.\n\n";
}
void getScore(double & score)
{
static double tScore;
tScore++;
cout << "Please enter a test score. ";
cin >> tScore;
while (tScore < 0 || tScore > 100)
{
cout << "Valid test scores range from 0 - 100.\n";
cout << "Please enter a test score. ";
cin >> tScore;
}
}
void calcAverage(double grd1, double grd2, double grd3, double grd4, double grd5)
{
double lowest;
double sum;
double average;
cout << grd1;
lowest = findLowest(grd1, grd2, grd3, grd4, grd5);
sum = (grd1 + grd2 + grd3 + grd4);
average = (sum / 4);
cout << "The average of the four highest test scores is "<<
average << ".\n\n";
}
int findLowest(double tScore1, double tScore2, double tScore3, double tScore4, double tScore5)
{
double lowest = tScore1;
if (lowest > tScore2)
lowest = tScore2;
if (lowest > tScore3)
lowest = tScore3;
if (lowest > tScore4)
lowest = tScore4;
if (lowest > tScore5)
lowest = tScore5;
return 0;
}
|