Alexander_B

On Time For Exam 87/100

Feb 3rd, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 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 DomashnoOnTimeForTheExam
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. // get input --> int hourExam; int minuteExam; int hourArive; int minuteArive;
  14.  
  15. int hourExam = int.Parse(Console.ReadLine());
  16. int minuteExam = int.Parse(Console.ReadLine());
  17. int hourArive = int.Parse(Console.ReadLine());
  18. int minuteArive = int.Parse(Console.ReadLine());
  19.  
  20. // decide if late, on time or early
  21.  
  22. string lateTimeEarly = "0";
  23. double minutesDifference = (hourExam * 60 + minuteExam) - (hourArive * 60 + minuteArive);
  24.  
  25. if (hourExam == hourArive && minuteExam == minuteArive)
  26. {
  27. lateTimeEarly = "onTimeExactly";
  28. }
  29. else if (minutesDifference > 0 && minutesDifference <= 30)
  30. {
  31. lateTimeEarly = "onTime";
  32. }
  33. else if (minutesDifference > 30)
  34. {
  35. lateTimeEarly = "early";
  36. }
  37. else
  38. {
  39. lateTimeEarly = "late";
  40. }
  41.  
  42. // set firstRowToPrint
  43.  
  44. string firstRowToPrint = "0";
  45.  
  46. switch (lateTimeEarly)
  47. {
  48. case "onTimeExactly":
  49. case "onTime":
  50. firstRowToPrint = "On time";
  51. break;
  52. case "early":
  53. firstRowToPrint = "Early";
  54. break;
  55. case "late":
  56. firstRowToPrint = "Late";
  57. break;
  58.  
  59. }
  60.  
  61. Console.WriteLine(firstRowToPrint);
  62.  
  63. // if function with if <-1 if he is late and else if >1 if he is early and set print for second row
  64.  
  65. if (minutesDifference < -1)
  66. {
  67. if (minutesDifference > -60)
  68. {
  69. double minutesToPrint = Math.Abs(minutesDifference);
  70. Console.WriteLine($"{minutesToPrint} minutes after the start");
  71. }
  72. else if (minutesDifference <= -60)
  73. {
  74. double hourToPrint = Math.Floor(Math.Abs(minutesDifference) / 60);
  75. double minutesToPrint = Math.Abs(minutesDifference) % 60;
  76. if (minutesToPrint >= 0 && minutesToPrint <= 9)
  77. {
  78. Console.WriteLine($"{hourToPrint}:0{minutesToPrint} hours after the start");
  79. }
  80. else
  81. {
  82. Console.WriteLine($"{hourToPrint}:{minutesToPrint} hours after the start");
  83. }
  84. }
  85. }
  86. else if (minutesDifference > 1)
  87. {
  88. if (minutesDifference < 60)
  89. {
  90. double minutesToPrint = minutesDifference;
  91. Console.WriteLine($"{minutesToPrint} minutes before the start");
  92. }
  93. else if (minutesDifference >= 60)
  94. {
  95. double hourToPrint = Math.Floor(minutesDifference / 60);
  96. double minutesToPrint = minutesDifference % 60;
  97. if (minutesToPrint >= 0 && minutesToPrint <= 9)
  98. {
  99. Console.WriteLine($"{hourToPrint}:0{minutesToPrint} hours before the start");
  100. }
  101. else
  102. {
  103. Console.WriteLine($"{hourToPrint}:{minutesToPrint} hours before the start");
  104. }
  105. }
  106. }
  107.  
  108. // decide if he is late or early
  109. // calculate with how many hours and how many minutes
  110. // set secondRowToPrint
  111. // print secondRow
  112.  
  113. }
  114. }
  115. }
Add Comment
Please, Sign In to add comment