- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Assignment_3_Question_5
- {
- class Program
- {
- //creating public arrays for racers and time
- static string[] racers = new string[3];
- static int[] rtime = new int[3];
- //main method
- static void Main(string[] args)
- {
- //delcaring final ordered racer and time variables
- string racer1 = "";
- string racer2 = "";
- string racer3 = "";
- int rtime1 = 0;
- int rtime2 = 0;
- int rtime3 = 0;
- //title
- //do loop for program to continue until user wants to exit
- //do loop to check for errors in inputted data
- int count = 0;
- do
- {
- //asks user for input
- Console.WriteLine("Please Enter Racer {0}", (count + 1));
- racers[count] = Console.ReadLine();//gets user input
- do
- {
- rtime[count] = GetRacerTime(count);//sets racer time array entry at what ever the counters at from the return value from the getracertime method
- } while (rtime[count] < 0 || rtime[count] >= 181);//continues until data is within the 0-180 data range thats excepted
- count++;
- } while (count <= 2);//while statement for do loop
- //calling setradius method from circle class/object to set inputted radius from user
- OrderRacers(ref racer1, ref racer2, ref racer3, ref rtime1, ref rtime2, ref rtime3);//caled orderracers method and passes the reference for variables so method modifies the original variables and not there own
- Console.WriteLine("");
- Console.WriteLine("-----------------------------------------");
- Console.WriteLine("| Fastest Time (in minutes) ");
- Console.WriteLine("| {0} {1} ", racer1, rtime1);
- Console.WriteLine("| {0} {1} ", racer2, rtime2);//displays output of the racers from fastest to slowest thats calculated from orderracers method
- Console.WriteLine("| {0} {1} ", racer3, rtime3);
- Console.WriteLine("| Slowest");
- Console.WriteLine("-----------------------------------------");
- Console.WriteLine("");
- Console.WriteLine("");
- }
- }
- public static void OrderRacers(ref string racer1, ref string racer2, ref string racer3, ref int rtime1, ref int rtime2, ref int rtime3)
- {
- //sets up counter and temp storage vars
- string temp = null;
- int tempn = 0;
- int count = 0;
- //continues in a loop to find the slowest racer
- while (count < 3)
- {
- if (rtime[count] > tempn)//compares new entry with the last slowest person found
- {
- temp = racers[count]; //if new slowest time is found its set to temp variable
- tempn = rtime[count]; //with the corresponding time
- }
- count++; //ups the counter
- }
- racer3 = temp;//unloads temp variables with slowest time into finalized variables that where passed on as reference
- rtime3 = tempn;
- //resets variables and functions like the last loop
- tempn = 0;
- count = 0;
- while (count < 3)
- {
- if (rtime[count] > tempn && rtime[count] != rtime3)
- {
- temp = racers[count];
- tempn = rtime[count];
- }
- count++;
- }
- racer2 = temp;
- rtime2 = tempn;
- //functions like last loop except finds the last remaining racer that was not added to the other entries making it the fastest entry (smallest number)
- tempn = 0;
- count = 0;
- while (count < 3)
- {
- if (rtime[count] != rtime2 && rtime[count] != rtime3)
- {
- racer1 = racers[count];
- rtime1 = rtime[count];
- }
- count++;
- }
- }
- public static int GetRacerTime(int count)
- {
- /*Temporary Variable to store output*/
- string temp;
- int output = -1;
- Console.WriteLine("Please Enter Time for Racer {0}", (count + 1));
- temp = Console.ReadLine();
- /*Try statement to attempt the variable data change*/
- try
- {
- /*converting a string to an int*/
- output = Convert.ToInt32(temp);
- if (output < 0 || output >= 181)
- //if statement to show error message if data is invalid
- {
- Console.WriteLine("----------Error-------");
- Console.WriteLine("|Error Invalid Number|");
- Console.WriteLine("----------------------");
- }
- else
- {
- count1++;
- }
- }
- }
- }
