Advertisement
Guest User

On Time for Exam

a guest
Apr 6th, 2016
1,988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 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 _03.On_Time_for_the_Exam
  8. {
  9.     class OnTimeForTheExam
  10.     {
  11.         static void Main(string[] args)
  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 totalExamMinutes = examHour * 60 + examMinutes;
  19.             int totalArriveMinutes = arriveHour * 60 + arriveMinutes;
  20.  
  21.             int difference = totalExamMinutes - totalArriveMinutes;
  22.  
  23.             int diffHours = 0;
  24.  
  25.  
  26.             if (difference == 0 || difference > 0 && difference <= 30)
  27.             {
  28.                 Console.WriteLine("On time");
  29.  
  30.                 if (difference != 0)
  31.                 {
  32.                     Console.WriteLine("{0} minutes before the start", difference);
  33.                 }
  34.                
  35.             }
  36.             else if (difference > 30)
  37.             {
  38.                 Console.WriteLine("Early");              
  39.  
  40.                 while (difference > 59)
  41.                 {
  42.                     diffHours++;
  43.                     difference -= 60;
  44.                 }
  45.  
  46.                 if (diffHours > 0)
  47.                 {
  48.                     Console.WriteLine("{0}:{1:00} hours before the start", diffHours, difference);
  49.                 }
  50.                 else
  51.                 {
  52.                     Console.WriteLine("{0} minutes before the start", difference);
  53.                 }
  54.  
  55.             }
  56.  
  57.             else
  58.             {
  59.                 Console.WriteLine("Late");
  60.  
  61.                 difference = Math.Abs(difference);
  62.  
  63.                 while (difference > 59)
  64.                 {
  65.                     diffHours++;
  66.                     difference -= 60;
  67.                 }
  68.  
  69.                 if (diffHours > 0)
  70.                 {
  71.                     Console.WriteLine("{0}:{1:00} hours after the start", diffHours, difference);
  72.                 }
  73.                 else
  74.                 {
  75.                     Console.WriteLine("{0} minutes after the start", difference);
  76.                 }
  77.             }
  78.  
  79.  
  80.  
  81.            
  82.                      
  83.  
  84.  
  85.  
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement