Using a C# program write a program that accepts any number of homework scores ranging in value from 0 through
10. Prompt the user for a new score if they enter a value outside of the specified range. Prompt
the user for a new value if they enter an alphabetic character. Store the values in an array.
Calculate the average excluding the lowest and highest scores. Display the average as well as the
highest and lowest scores that were discarded.

Respuesta :

Answer:

The program is written using C# Console

Comments are used for explanatory purpose

Program starts here

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication1

{

   class Program

   {

       static void Main(string[] args)

       {

           int num;

           Console.WriteLine("Enter digit: [0-10]");

           while (!int.TryParse(Console.ReadLine(), out num) || num<0||num>10)

           {

               Console.WriteLine("That was invalid. Enter a valid digit.");

           }

           //Declare scores

           int[] scores = new int[num];

           //Accept Input

           for(int i =0;i<num;i++)

           {

               Console.WriteLine("Enter Test Score "+(i+1));

               while (!int.TryParse(Console.ReadLine(), out scores[i]))

               {

                   Console.WriteLine("That was invalid. Enter a valid digit.");

                   Console.WriteLine("Enter Test Score " + (i + 1));

               }

           }

           //Determine highest

           int max = scores[0];

           for (int i = 1; i < num; i++)

           {

               if (scores[i] > max)

               {

                   max = scores[i];

               }

           }

           //Determine Lowest

           int least = scores[0];

           for (int i = 1; i < num; i++)

           {

               if (scores[i] < least)

               {

                   least = scores[i];

               }

           }

           int sum = 0;

           //Calculate total

           for(int i =0; i< num;i++)

           {

               sum += scores[i];

           }

           //Subtract highest and least values

           sum = sum - least - max;

           //Calculate average

           double average = sum / (num - 2);

           //Print Average

           Console.WriteLine("Average = "+average);

           //Print Highest

           Console.WriteLine("Highest = " + max);

           //Print Lowest

           Console.WriteLine("Lowest = " + least);

           Console.ReadLine();  

       }

   }

}

See Attachment for program source file in txt

Ver imagen MrRoyal