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


Expert's answer
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");
            for (var i = 0; i < numberOfSurfers; i++)
                storage[i] = getPoints();
            var storageCopy = makeCopy(storage);

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

        static int getHighest(int[] 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!


No comments. Be the first!

Leave a comment

New on Blog