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 82 83 84 85 86 87 88 89
|
#include <iostream>
using namespace std;
void getScore(double &grade);
void calcAverage(double,double,double,double,double);
int findLowest(double,double,double,double,double);
int main()
{
double grade1, grade2, grade3, grade4, grade5;
getScore(grade1);
getScore(grade2);
getScore(grade3);
getScore(grade4);
getScore(grade5);
calcAverage(grade1,grade2,grade3,grade4,grade5);
}
void getScore(double &grade)
{
static int count = 0;
count++;
cout << "Please enter in grade number " << count << ": ";
cin >> grade;
if ( grade < 0 || grade > 100 )
{
do
{
cout << "Please enter in a valid number 0 through 100: ";
cin >> grade;
}
while (grade < 0 || grade > 100 );
}
}
void calcAverage(double score1, double score2, double score3, double score4, double score5)
{
double lowest;
double average;
lowest = findLowest(score1,score2,score3,score4,score5);
average = ((score1 + score2 + score3 + score4 + score5) - lowest) / 04;
cout << "After dropping the lowest test score , the test average is " << average << endl;
}
int findLowest(double grad1, double grad2, double grad3, double grad4, double grad5)
{
double average,
least,
lowDrop = 0;
average = (grad1 + grad2 + grad3 + grad4 + grad5) / 5;
cout << "The average before dropping the lowest grade: " << average << endl;
if(grad1 < 100)
{
least = grad1;
lowDrop = grad1;
return lowDrop;
}
else if(grad2 < 100)
{
least = grad2;
lowDrop = grad2;
return lowDrop;
}
else if(grad3 < 100)
{
least = grad3;
lowDrop = grad3;
return lowDrop;
}
else if(grad4 < 100)
{
least = grad4;
lowDrop = grad4;
return lowDrop;
}
else if(grad5 < 100)
{
least = grad5;
lowDrop = grad5;
return lowDrop;
}
}
| |