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
|
#include <iostream>
using namespace std;
void printMessage(); //Prototype for printMessage
void getScore(int&); //Prototype for getScore with reference variable
int findLowest(int,int,int,int,int,int &); //Prototype for findLowest with reference variable
int main()
{
printMessage(); //Calls printMessage
//Variables for test scores
int score1, score2, score3, score4, score5;
int low;
//Calls the getScore method for each
getScore(score1);
getScore(score2);
getScore(score3);
getScore(score4);
getScore(score5);
findLowest(score1,score2,score3,score4,score5,low);
}
//*******************Functions***********************************
void getScore(int &testScore)
{
cout << "Enter the test score: ";
cin >> testScore;
while(testScore < 0 || testScore > 100)
{
printMessage();
cout << "The score must be in the range of 0-100.\n\n";
cout << "Enter the test score: ";
cin >> testScore;
cout <<endl;
}
}
int findLowest(int score1, int score2, int score3, int score4, int score5, int &lowest)
{
if(score1 < score2)
lowest = score1;
else if(score2 < score1)
lowest = score2;
if(score3 < lowest)
lowest = score3;
if(score4 < lowest)
lowest = score4;
if(score5 < lowest)
lowest = score5;
cout << "The lowest test score is " << lowest << endl;
}
void printMessage()
{ cout <<endl;
cout <<"This program finds the average of a group of 5 test scores.\nThe lowest score in the group is dropped.\n"<<endl;
}
|