Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your teacher runs a lot of marathons. Write a program to allow him to find his f

ID: 3794959 • Letter: Y

Question

Your teacher runs a lot of marathons. Write a program to allow him to find his fastest, slowest and average time of up to 10 races. Your program should ask for times for each race in hours, minutes and seconds. After 10 races have been entered or the user has typed -1 (to indicate the end of input) you will provide the following

output: Race 1: {time} Race 2: {time} **FASTEST** .... .... Race {n-1}: {time} **SLOWEST** Race {n}: {time} Average time: {time}

You will need to store the input in an array so that you can output them at the end. Obviously the words FASTEST and SLOWEST should be on the correct line. You may not use any built in functions on the arrays to calculate the fastest, slowest and average. Average should be rounded to the closest second. The language is C#.

Explanation / Answer

using System;

public class Test
{
   public static void Main()
   {
    
   int race,hours,minutes,seconds,fastIndex,slowIndex;
   fastIndex=slowIndex = 0;
   double[] timeSec= new double[10];
   double totalTimeSec = 0;
   double fastest = 0;
   double slowest = 999999;

   for(race = 0;race < 10; race++) // enter hours,minutes and seconds for 10 races
   {
      Console.WriteLine("Enter time in hours,minutes and seconds");
      hours = Convert.ToInt32(Console.Read());
      minutes = Convert.ToInt32(Console.Read());
      seconds = Convert.ToInt32(Console.Read());
      timeSec[race] = hours*60*60+minutes+minutes*60+seconds;
      totalTimeSec = totalTimeSec + timeSec[race];
   }

      for(race = 0;race < 10; race++)
      {
      if(timeSec[race] < slowest)
      {
          slowest = timeSec[race];   //find lowest time or fastest race
   
          fastIndex = race;
      }
      }
      //Console.WriteLine("fastest :"+fastIndex);

       for(race = 0;race < 10; race++)
      {
      if(timeSec[race] > fastest) //find higest time or slowest eace
      {
         fastest = timeSec[race];
   
          slowIndex = race;
      }
   
      }
   


      for(race = 0;race < 10; race++)
      {
   
      if(race == fastIndex)
      Console.WriteLine("Race "+(race+1)+":"+ timeSec[race]+" **FASTEST**");
      else if(race == slowIndex)
      Console.WriteLine("Race "+(race+1)+":"+ timeSec[race]+" **SLOWEST**");
      else
      Console.WriteLine("Race "+(race+1)+":"+ timeSec[race]);
      }

      Console.WriteLine("Average time of 10 race : "+totalTimeSec/10+" Seconds");
   }
}

output: