Advertisement
radostina92

Untitled

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