Здравейте,
Условието на задачата е: * 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
ornon-beer time
according to the definition above orinvalid time
if the time cannot be parsed.
Като тук не намирам начин да спазя тази част от условието:
an hour in range [01…12], a minute in range [00…59] and AM / PM designator.
А ето го и решението ми дотук:
Console.Write("PLease enter what time is it: ");
string userTime = Console.ReadLine();
DateTime time;
bool isParsed = DateTime.TryParse(userTime, out time);
if (!isParsed)
{
Console.WriteLine("invalid time");
}
else if (time < DateTime.Parse("03:00 AM") || time >= DateTime.Parse("01:00 PM"))
{
Console.WriteLine("beer time.");
}
else
{
Console.WriteLine("non-beer time.");
}
}
Благодаря предварително,
Симона