Advertisement
IvanITD

08.OnTimeForTheExam

Jan 18th, 2024
1,060
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | Source Code | 0 0
  1. int examHour = int.Parse(Console.ReadLine());
  2. int examMinutes = int.Parse(Console.ReadLine());
  3. int arivalHour = int.Parse(Console.ReadLine());
  4. int arivalMinutes = int.Parse(Console.ReadLine());
  5.  
  6.  
  7. int examToMinute = examHour * 60;
  8. int arivalToMinutes = arivalHour * 60;
  9.  
  10. int totalExamMinuteTime = examToMinute + examMinutes;
  11. int totalArivalMinuteTime = arivalToMinutes + arivalMinutes;
  12.  
  13. int totalTime = Math.Abs(totalExamMinuteTime - totalArivalMinuteTime);
  14.  
  15. int hour = totalTime / 60;
  16. int minutes = totalTime % 60;
  17.  
  18. if (totalExamMinuteTime < totalArivalMinuteTime) // If the student is late
  19. {
  20.     Console.WriteLine("Late");
  21.     if (hour == 0)
  22.     {
  23.         Console.WriteLine($"{minutes} minutes after the start");
  24.     }
  25.     else
  26.     {
  27.         Console.WriteLine($"{hour}:{minutes:D2} hours after the start");
  28.     }
  29. }
  30. else if (totalExamMinuteTime == totalArivalMinuteTime) // If the student is on time
  31. {
  32.     Console.WriteLine("On time");
  33.    
  34. }
  35. else if (totalTime <= 30)
  36. {
  37.     Console.WriteLine("On time");
  38.     Console.WriteLine($"{minutes} minutes before the start");
  39. }
  40. else if (totalExamMinuteTime > totalArivalMinuteTime || totalTime > 30) // If the student is early
  41. {
  42.     Console.WriteLine("Early");
  43.     if (hour == 0)
  44.     {
  45.         Console.WriteLine($"{minutes} minutes before the start");
  46.     }
  47.     else
  48.     {
  49.         Console.WriteLine($"{hour}:{minutes:D2} hours before the start");
  50.     }
  51. }
  52.  
  53.  
  54.  
  55.  
Tags: C#
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement