Answer to Question #216822 in C# for livy

Question #216822
  • Write a program that can be used to determine the winner of a local surfing competition. Your program must do the following:Make use of an array to store the points obtained by the competitor
  • When creating the array, use 10 as the maximum number of surfers in the competition
  • Prompts the user for the actual number of surfers in the competition, then uses getPoints to populate the array
  • Duplicate the array to have a copy to work on, but keep the original unchanged (use makeCopy to do this)
  • Determines the highest number of points by using build in array methods to sort the elements in the working copy of the array in descending order (uses getHighest to do this)
  • Displays the data

 




1
Expert's answer
2021-07-13T17:20:20-0400
using System;


namespace trip
{
    class Program
    {
        private static Random rnd = new Random();
        static void Main(string[] args)
        {
            var storage = new int[10];
            var numberOfSurfers = int.Parse(Console.ReadLine());


            if (numberOfSurfers > 10)
            {
                Console.WriteLine("Number of surfers: 1-10");
                return;
            }
                
            for (var i = 0; i < numberOfSurfers; i++)
            {
                storage[i] = getPoints();
            }
            
            var storageCopy = makeCopy(storage);


            var highestScore = getHighest(storageCopy);
            Console.WriteLine("=====Highest Score=====");
            Console.WriteLine(highestScore);
        }


        static int getHighest(int[] arr)
        {
            Array.Sort(arr);
            Array.Reverse(arr);
            return arr[0]; ;
        }


        static int[] makeCopy(int[] arr)
        {
            int[] newArr = new int[arr.Length];
            arr.CopyTo(newArr, 0);
            return newArr;
        }


        static int getPoints()
        {
            var points = rnd.Next(1, 10);
            return points;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS