Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-09-29
3
Medium Priority
?
235 Views
Last Modified: 2012-05-05
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);
            }
        }
    }
0
Comment
Question by:jpmc_cmsops
  • 2
3 Comments
 

Author Comment

by:jpmc_cmsops
ID: 22595113
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
 
LVL 2

Accepted Solution

by:
CAnuszczyk earned 2000 total points
ID: 22595325
private void CalculateAvg()
        {
            int total = 0;
            foreach (int c in _scoreCount)
                total += c;

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

0
 

Author Closing Comment

by:jpmc_cmsops
ID: 31501134
Thank you!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question