# I am trying to use arrays to calculate avg of scores disregarding min and max values.

I tried to figure in the subtraction of the minimum and maximum value but the average does calculate correctly; I know I need to alter the (_scoreCount.Count); also, but I am not sure how. Can anyone help me with that?

class ScoreInput
{

private List<int> _scoreCount;
private double _avg;
private int _maxCnt;
private int _minCnt;

public ScoreInput()
{
_scoreCount = new List<int>();
}

public double Avg
{
get
{
CalculateAvg();
return _avg;
}
}

public double MaxCnt
{
get
{
DetermineMax();
return _maxCnt;
}
}

public double MinCnt
{
get
{
DetermineMin();
return _minCnt;
}
}

private void CalculateAvg()
{
int total = 0;
foreach (int c in _scoreCount)
total += (c - (_maxCnt + _minCnt));
_avg = total / _scoreCount.Count;
}

private void DetermineMax()
{
int maxCntIndex = 0;
for (int i = 1; i < _scoreCount.Count; i++)
if (_scoreCount[i] > _scoreCount[maxCntIndex])
maxCntIndex = i;
_maxCnt = _scoreCount[maxCntIndex];
}

private void DetermineMin()
{
int minCntIndex = 0;
for (int i = 1; i < _scoreCount.Count; i++)
if (_scoreCount[i] < _scoreCount[minCntIndex])
minCntIndex = i;
_minCnt = _scoreCount[minCntIndex];
}

public void GetData()
{
Console.Write("Enter a Score: ");
string inValue = Console.ReadLine();
try
{
_scoreCount.Add(Convert.ToInt32(inValue));
}
catch (Exception e)
{
}
}
}

class Program
{
static void Main(string[] args)
{
ScoreInput scores = new ScoreInput();

Console.WriteLine();
Console.WriteLine();
while (true)
{
scores.GetData();
Console.WriteLine("The Average Score is {0}", scores.Avg);
Console.WriteLine("The Max Score is {0}", scores.MaxCnt);
Console.WriteLine("The Min Score is {0}", scores.MinCnt);
}
}
}
Asked:
###### Who is Participating?

Commented:
private void CalculateAvg()
{
int total = 0;
foreach (int c in _scoreCount)
total += c;

total -= (_maxCnt + _minCnt );
_avg = total / _scoreCount.Count;
}

0

Author Commented:
My mistake I need to calculate the Percentage of all scores minus the max and min values; for example:
With these scores {100, 95, 90, 80, 85} ; it would only calculate: ((95 + 90 + 80) / 100). Thank you for anyone's help.
0

Author Commented:
Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Already a member? Login.

All Courses

From novice to tech pro — start learning today.