//Written by mark lair
//Oct. 2, 2007
//Chapter 6
//Assignment 8, Drop the lowest score and average
//this program will calculate the averege of a group of test scores entered 
//the lowest of the 5 will be dropped

#include <iostream>
#include <iomanip>
using namespace std;

// function prototypes

void getScore(int &);
void calcAverage(int, int, int, int, int);
int findLowest(int, int, int, int, int);

int main()
{
	int score1;
	int score2;
	int score3;
	int score4;
	int score5;
	
	cout << "Enter 5 test scores and I will drop the lowest and calculate the average." << endl;


	getScore(score1);
	getScore(score2);
	getScore(score3);
	getScore(score4);
	getScore(score5);

	calcAverage(score1, score2, score3, score4, score5);

	system("pause");
	return 0;

}

void getScore(int &refScore)
{

	cout << "Enter a test score: ";
	cin >> refScore;
	
	// validate input 
	while (refScore < 0 || refScore > 100)
	{
		cout << "Your test score should be \n";
		cout << "between 0 and 100.\n";
		cout << "Please enter another test score: ";
		cin >> refScore;

	}


}

void calcAverage(int sc1, int sc2, int sc3, int sc4, int sc5)
{
	int sum;
	int average;

	sum = sc1 + sc2 + sc3 + sc4 + sc5;
	average = (sum - findLowest(sc1, sc2, sc3, sc4, sc5)) / 4;
	
	cout << "The average of the four highest test scores \n";
	cout << "is " << average << " with \n";
	cout << findLowest(sc1, sc2, sc3, sc4, sc5) << " being the lowest!" << endl;


}




int findLowest(int a, int b, int c, int d, int e)
{
	int lowest = 100;
	
	if (a < lowest)
		lowest = a;
	if (b < lowest)
		lowest = b;
	if (c < lowest)
		lowest = c;
	if (d < lowest)
		lowest = d;
	if (e < lowest)
		lowest = e;

	return lowest;
	
}


