Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Threading;
- //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” (an hour in range [01...12], a minute in range [00…59] and AM / PM designator) and prints “beer time” or “non-beer time” according to the definition above or “invalid time” if the time cannot be parsed. Note that you may need to learn how to parse dates and times. Examples:
- class BeerTime
- {
- static void Main ()
- {
- Console.Write("Enter what time it is now, but in format (hh:mm tt): ");
- string input = Console.ReadLine();
- DateTime time;
- DateTime start = DateTime.Parse("1:00 PM");
- DateTime end = DateTime.Parse("3:00 AM");
- if (DateTime.TryParse(input, out time))
- {
- if ((time > start) || (time < end))
- {
- Console.WriteLine("Beer time");
- }
- else
- {
- Console.WriteLine("Non-beer time");
- }
- }
- else
- {
- Console.WriteLine("Invalid time.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement