int findLowest() should find and return the lowest of the five scores passed to it. It should be called by calcAverage, who uses the function to determine which of the five scores to drop.
void calcAverage() should calculate and display the average of the four highest scores. This function should be called once just by main, and should be passed the five scores
Code:
#include <iostream>
using namespace std;
void getScore(int &);
void calcAverage();
int findLowest(int, int, int, int, int);
int score1, score2, score3, score4, score5, lowest;
int main()
{
getScore(score1);
getScore(score2);
getScore(score3);
getScore(score4);
getScore(score5);
calcAverage();
}
void getScore(int &score)
{
cout << "Test score? ";
cin >> score;
while (score < 0 || score > 100)
{
cout << "Test score cannot be lower than 0 or higher than 100.\n";
cout << "Test score? ";
cin >> score;
}
}
int findLowest(int score1, int score2, int score3, int score4, int score5)
{
lowest = score1;
if (score2 < lowest)
lowest = score2;
if (score3 < lowest)
lowest = score3;
if (score4 < lowest)
lowest = score4;
if (score5 < lowest)
lowest = score5;
return lowest;
}
void calcAverage()
{
findLowest(score1, score2, score3, score4, score5);
if (lowest == score1)
score1 = 0;
if (lowest == score2)
score2 = 0;
if (lowest == score3)
score3 = 0;
if (lowest == score4)
score4 = 0;
if (lowest == score5)
score5 = 0;
double average;
average = (static_cast<double>(score1) + score2 + score3 + score4 + score5) / 4;
cout << "The average of the four highest scores is " << average << endl;
}
thanks