BorislavBorisov

Check isTime correct

Oct 3rd, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2.  
  3. class CheckTime
  4. {
  5.     static void Main()
  6.     {
  7.         Console.WriteLine("What time is now?");
  8.         Console.Write("Whrite hours: ");
  9.         int hours = int.Parse(Console.ReadLine());
  10.         Console.WriteLine("Write minutes: ");
  11.         int minutes = int.Parse(Console.ReadLine());
  12.         bool isValidTime = CheckValidateHours(hours) && CheckValidateMinutes(minutes);
  13.  
  14.         if (isValidTime)
  15.         {
  16.             Console.WriteLine("The Time is {0}:{1} now", hours, minutes);
  17.         }
  18.         else
  19.         {
  20.             Console.WriteLine("Incorect Time!");
  21.         }
  22.  
  23.     }
  24.  
  25.     private static bool CheckValidateMinutes(int minutes)
  26.     {
  27.        return minutes >= 0 && minutes <= 59;
  28.      
  29.     }
  30.  
  31.     private static bool CheckValidateHours(int hours)
  32.     {
  33.         bool result = hours >= 0 && hours <= 23;
  34.         return result;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment