Array exercise #3

PHOTO EMBED

Fri Dec 18 2020 04:53:50 GMT+0000 (Coordinated Universal Time)

Saved by @Javkhlantugs ##c#

            //Write code that reads an unspecified number of scores and determines how many scores are above or equal 
            //to the average and how many scores are below the average.
            //Enter a negative number to signify the end of the input.Assume that the maximum number of scores is 100.

            int[] scores = new int[10];
            int count = 0, total = 0; 

            for(int i = 0; i < scores.Length; i++)
            {
                Console.Write($"Enter the score: ");
                int score = int.Parse(Console.ReadLine()); 
                if (score < 0)
                {
                    break;
                }
                scores[i] = score;
                total += score; 
                count++;
            }

            double average = total / count;
            int aboveOrEqualToAverage = 0, belowAverage = 0; 
            for(int i = 0; i < count; i++)
            {
                if(scores[i] >= average)
                {
                    aboveOrEqualToAverage++; 
                }
                else
                {
                    belowAverage++; 
                }
            }
            Console.WriteLine($"Average : {average}");
            Console.WriteLine($"Scores above or equal to the average {aboveOrEqualToAverage}");
            Console.WriteLine($"Scores below the average: {belowAverage}");
content_copyCOPY