Advertisement
Gesh4o

BeerTime

Sep 21st, 2015
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. using System;
  2.  
  3. class BeerTime
  4. {
  5. static void Main()
  6. {
  7. /*
  8. 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. E
  9. */
  10.  
  11. DateTime startBeerTime = DateTime.Parse("1:00 PM");
  12. DateTime endBeerTime = DateTime.Parse("3:00 AM");
  13. int startBeerHour = startBeerTime.Hour;
  14. int endBeerHour = endBeerTime.Hour;
  15. int beerTime = time.Hour;
  16.  
  17. if ((beerTime >=startBeerHour) && (beerTime < (endBeerHour+14)))
  18.  
  19. {
  20. Console.WriteLine("beer time");
  21. }
  22. else
  23. {
  24. Console.WriteLine("non-beer time");
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement