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>
#include <iomanip>
using namespace std;
void getScore(int &score);
void calcAverage(int score1, int score2, int score3, int score4, int score5, int lowest);
int findLowest(int score1, int score2, int score3, int score4, int score5);
int main ()
{
int score1 = 0, score2 = 0, score3 = 0, score4 = 0, score5 = 0, lowest = 0;
getScore(score1);
getScore(score2);
getScore(score3);
getScore(score4);
getScore(score5);
findLowest(score1, score2, score3, score4, score5);
calcAverage(score1, score2, score3, score4, score5, lowest);
system ("pause");
return 0;
}
void getScore(int &score)
{
// for (int repeat = 0; repeat < 5; repeat++)
//{
cout << "Enter a test score between 0 and 100: ";
cin >> score;
cout << "\n\n";
while ((score < 0) || (score > 100))
{
cout << "Invalid Input.\n\nEnter a test score between 0 and 100: ";
cin >> score;
cout << "\n\n";
}
//}
}
int findLowest(int score1, int score2, int score3, int score4, int score5)
{
int lowest = score1;
if (score2 < lowest)
{
lowest = score2;
}
if (score3 < lowest)
{
lowest = score3;
}
if (score4 < lowest)
{
lowest = score4;
}
if (score5 < lowest)
{
lowest = score5;
}
cout << "The lowest test score is " << lowest << "\n\n";
return lowest;
}
void calcAverage(int score1, int score2, int score3, int score4, int score5, int lowest)
{
double average;
average = ((score1 + score2 + score3 + score4 + score5) - lowest) / 4.0;
cout << fixed << showpoint << setprecision(2);
cout << "\nThe average of the four highest scores is " << average << "\n\n\n";
}
|