Advertisement
dimipan80

5.10ConditionalStatements_BeerTime

Mar 21st, 2014
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using System.Globalization;
  4.  
  5. class BeerTime
  6. {
  7.     static void Main ()
  8.     {
  9.         Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  10.         Console.Write(@"Please, enter your time in format ""hh:mm TT"",
  11. (example 05:30 PM),  YOUR TIME = ");
  12.         string timeStr = Console.ReadLine();
  13.         DateTime customTime;
  14.         if (DateTime.TryParse(timeStr, out customTime))
  15.             Console.WriteLine("Converted '{0}' to {1} ({2}).", timeStr, customTime,
  16.                               customTime.Kind);
  17.         else
  18.         {
  19.             Console.WriteLine("'{0}' is not in an acceptable format.", timeStr);
  20.             Console.WriteLine("Error - Invalid Time !!!");
  21.             Console.ReadLine();
  22.             return;
  23.         }
  24.  
  25.         DateTime startBeerTime = DateTime.Parse("01:00 PM");
  26.         DateTime endBeerTime = DateTime.Parse("03:00 AM");
  27.         if ((customTime >= endBeerTime) && (customTime < startBeerTime))
  28.         {
  29.             Console.WriteLine("Now is NON-BEER TIME !");
  30.         }
  31.         else
  32.         {
  33.             Console.WriteLine("Now is BEER TIME !");
  34.         }      
  35.         Console.ReadLine();
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement