Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //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.
- namespace BeerTime
- {
- class BeerTime
- {
- static void Main()
- {
- Console.Write("Hour: ");
- int n = int.Parse(Console.ReadLine());
- Console.Write("Minutes: ");
- int m = int.Parse(Console.ReadLine());
- TimeSpan ts = new TimeSpan(n, m, 00);
- DateTime dtTemp = DateTime.ParseExact(ts.ToString(), "HH:mm:ss", CultureInfo.InvariantCulture);
- string str = dtTemp.ToString("hh:mm tt");
- Console.WriteLine(str);
- if (n < 3 || n > 13)
- {
- Console.WriteLine("Beer time");
- }
- else
- {
- Console.WriteLine("non-beer time");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement