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
|
#include <iostream>
using namespace std;
int getScore(int userInput);
int calcAverage(int testScore1, int testScore2, int testScore3, int testScore4, int testScore5, int lowest, int avgMinusLowest);
int findLowest(int testScore1, int testScore2, int testScore3, int testScore4, int testScore5);
int main()
{
int testScore1, testScore2, testScore3, testScore4, testScore5, lowest, average, avgMinusLowest;
testScore1 = getScore(testScore1);
testScore2 = getScore(testScore2);
testScore3 = getScore(testScore3);
testScore4 = getScore(testScore4);
testScore5 = getScore(testScore5);
lowest = findLowest(testScore1, testScore2, testScore3, testScore4, testScore5);
cout << "The lowest score is: " << lowest << endl;
average = calcAverage(testScore1, testScore2, testScore3, testScore4, testScore5, lowest, avgMinusLowest);
cout << "The average is " << average << endl;
return 0;
}
int getScore(int 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(int testScore1, int testScore2, int testScore3, int testScore4, int testScore5, int lowest, int avgMinusLowest)
{
lowest = findLowest(testScore1, testScore2, testScore3, testScore4, testScore5);
avgMinusLowest = ((testScore1 + testScore2 + testScore3 + testScore4 + testScore5 - lowest) / 5);
return avgMinusLowest;
}
int findLowest(int testScore1, int testScore2, int testScore3, int testScore4, int testScore5)
{
int 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;
return lowest;
}
|