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
|
#include <iostream>
#include <iomanip>
using namespace std;
int getScore(double userInput);
int calcAverage(double testScore1, double testScore2, double testScore3, double testScore4, double testScore5, double lowest, double avgMinusLowest);
int findLowest(double testScore1, double testScore2, double testScore3, double testScore4, double testScore5);
int main()
{
double testScore1 = 0, testScore2 = 0, testScore3 = 0, testScore4 = 0, testScore5 = 0, lowest = 0, average, avgMinusLowest = 0;
testScore1 = getScore(testScore1);
testScore2 = getScore(testScore2);
testScore3 = getScore(testScore3);
testScore4 = getScore(testScore4);
testScore5 = getScore(testScore5);
average = calcAverage(testScore1, testScore2, testScore3, testScore4, testScore5, lowest, avgMinusLowest);
cout << "The average is " << average << endl;
return 0;
}
int getScore(double userInput)
{
cout << "Enter a test score: ";
cin >> userInput;
while (userInput < 1 || userInput > 100)
{
cout << "Error! You must enter a value from 0-100. Try again: ";
cin >> userInput;
}
return userInput;
}
int calcAverage(double testScore1, double testScore2, double testScore3, double testScore4, double testScore5, double lowest, double avgMinusLowest)
{
lowest = findLowest(testScore1, testScore2, testScore3, testScore4, testScore5);
avgMinusLowest = ((testScore1 + testScore2 + testScore3 + testScore4 + testScore5 - lowest) / 4);
cout << fixed << showpoint << setprecision(2);
return avgMinusLowest;
}
int findLowest(double testScore1, double testScore2, double testScore3, double testScore4, double testScore5)
{
double lowest;
lowest = testScore1;
if (testScore2 < lowest)
lowest = testScore2;
else if (testScore3 < lowest)
lowest = testScore3;
else if (testScore4 < lowest)
lowest = testScore4;
else if (testScore5 < lowest)
lowest = testScore5;
cout << "The lowest score is: " << lowest << endl;
return lowest;
}
|