Advertisement
Guest User

Code

a guest
Jul 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ArriveOnTime
  8. {
  9.     class ArriveOnTime
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var examHour = int.Parse(Console.ReadLine());
  14.             var examMinutes = int.Parse(Console.ReadLine());
  15.             var hourArrive = int.Parse(Console.ReadLine());
  16.             var minArrive = int.Parse(Console.ReadLine());
  17.  
  18.             string late = "Late";
  19.             string onTime = "On time";
  20.             string early = "Early";
  21.  
  22.             int examTime = (60 * examHour) + examMinutes;
  23.             int arriveTime = (60 * hourArrive) + minArrive;
  24.  
  25.             int totalMinutesArrival = arriveTime - examTime;
  26.  
  27.             string studentArrival = string.Empty;
  28.             if (totalMinutesArrival < -30)
  29.             {
  30.                 studentArrival = early;
  31.             }
  32.             else if (totalMinutesArrival <= 30)
  33.             {
  34.                 studentArrival = onTime;
  35.             }
  36.             else
  37.             {
  38.                 studentArrival = late;
  39.             }
  40.  
  41.             string result = string.Empty;
  42.             if (totalMinutesArrival != 0)
  43.             {
  44.                 int hoursDifference = Math.Abs(totalMinutesArrival / 60);
  45.                 int minutesDifference = Math.Abs(totalMinutesArrival % 60);
  46.  
  47.                 if (hoursDifference > 0)
  48.                 {
  49.                     result = string.Format("{0}:{1:00} hours", hoursDifference, minutesDifference);
  50.                 }
  51.                 else
  52.                 {
  53.                     result = minutesDifference + " minutes";
  54.                 }
  55.                 if (totalMinutesArrival < 0)
  56.                 {
  57.                     result += " before the start";
  58.                 }
  59.                 else
  60.                 {
  61.                     result += " after the start";
  62.                 }
  63.             }
  64.  
  65.             Console.WriteLine(studentArrival);
  66.             if (!string.IsNullOrEmpty(result))
  67.             {
  68.                 Console.WriteLine(result);
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement