Dianov

Conditional Statements Advanced - Exercise (08. On Time for the Exam)

Nov 14th, 2020 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 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 OnTimeForTheExam
  8. {
  9.     class Program
  10.     {
  11.         public static void Main()
  12.         {
  13.             int examHour = int.Parse(Console.ReadLine());
  14.             int examMinutes = int.Parse(Console.ReadLine());
  15.             int arriveHour = int.Parse(Console.ReadLine());
  16.             int arriveMinutes = int.Parse(Console.ReadLine());
  17.  
  18.             int hour1 = examHour * 60 + examMinutes;
  19.             int hour2 = arriveHour * 60 + arriveMinutes;
  20.  
  21.             if (hour1 > hour2 && (hour1 - hour2) > 30)
  22.             {
  23.                 Console.WriteLine("Early");
  24.                 int minutesEarlier = hour1 - hour2;
  25.                 if (minutesEarlier < 60)
  26.                 {
  27.                     Console.WriteLine($"{Math.Abs(minutesEarlier)} minutes before the start");
  28.                 }
  29.                 else if (minutesEarlier >= 60)
  30.                 {
  31.                     int hours = minutesEarlier / 60;
  32.                     int minutes = minutesEarlier % 60;
  33.                     if (minutes < 10)
  34.                         Console.WriteLine($"{hours}:0{minutes} hours before the start");
  35.                     else if (minutes >= 10)
  36.                         Console.WriteLine($"{hours}:{minutes} hours before the start");
  37.                 }
  38.             }
  39.             else if (hour1 == hour2)
  40.             {
  41.                 Console.WriteLine("On time");
  42.             }
  43.             else if (hour1 > hour2 && (hour1 - hour2) <= 30)
  44.             {
  45.                 Console.WriteLine("On time");
  46.                 int minutesEarlier = hour1 - hour2;
  47.                 Console.WriteLine($"{Math.Abs(minutesEarlier)} minutes before the start");
  48.             }
  49.             else if (hour2 > hour1)
  50.             {
  51.                 Console.WriteLine("Late");
  52.                 if ((hour2 - hour1) < 60)
  53.                 {
  54.                     int minutes = hour2 - hour1;
  55.                     Console.WriteLine($"{minutes} minutes after the start");
  56.                 }
  57.                 else if ((hour2 - hour1) >= 60)
  58.                 {
  59.                     int hours = (hour2 - hour1) / 60;
  60.                     int minutes = (hour2 - hour1) % 60;
  61.                     if (minutes < 10)
  62.                         Console.WriteLine($"{hours}:0{minutes} hours after the start");
  63.                     else if (minutes >= 10)
  64.                         Console.WriteLine($"{hours}:{minutes} hours after the start");
  65.                 }
  66.             }
  67.         }
  68.     }
  69. }
Add Comment
Please, Sign In to add comment