Advertisement
kuruku

BeerTime

Apr 19th, 2014
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2.  
  3. //A beer time is after 1:00 PM and before 3:00 AM. Write a program that enters a time in format “hh:mm tt”
  4. //(an hour in range [01...12], a minute in range [00…59] and AM / PM designator) and prints “beer time” or
  5. //“non-beer time” according to the definition above or “invalid time” if the time cannot be parsed.
  6. //Note that you may need to learn how to parse dates and times.
  7.  
  8. namespace BeerTime
  9. {
  10.     class BeerTime
  11.     {
  12.         static void Main()
  13.         {
  14.  
  15.             Console.Write("Hour: ");
  16.             int n = int.Parse(Console.ReadLine());
  17.             Console.Write("Minutes: ");
  18.             int m = int.Parse(Console.ReadLine());
  19.  
  20.             TimeSpan ts = new TimeSpan(n, m, 00);
  21.             DateTime dtTemp = DateTime.ParseExact(ts.ToString(), "HH:mm:ss", CultureInfo.InvariantCulture);
  22.             string str = dtTemp.ToString("hh:mm tt");
  23.             Console.WriteLine(str);
  24.             if (n < 3 || n > 13)
  25.             {
  26.                 Console.WriteLine("Beer time");
  27.             }
  28.             else
  29.             {
  30.                 Console.WriteLine("non-beer time");
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement