Created
April 13, 2020 15:45
-
-
Save DreamerDeLy/446991a9498939d15a01891376c7aafa to your computer and use it in GitHub Desktop.
Task 14 [C#]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace Task14 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
DateTime date_now = DateTime.Now; | |
DateTime date_birth = new DateTime(); | |
Console.WriteLine("Enter your birth day:"); | |
date_birth = DateTime.Parse(Console.ReadLine()); | |
if (date_birth < date_now) | |
{ | |
DateTime delta = new DateTime((date_now - date_birth).Ticks); | |
Console.WriteLine($"Your age is {delta.Year-1} years, {delta.Month-1} months, {delta.Day-1} days."); | |
} | |
else | |
{ | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.WriteLine("ERROR: birth date is bigger then now"); | |
Console.ForegroundColor = ConsoleColor.Gray; | |
} | |
Console.ReadKey(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\AP\Task14>dotnet run | |
Enter your birth day: | |
03/11/2021 | |
ERROR: birth date is bigger then now | |
C:\AP\Task14>dotnet run | |
Enter your birth day: | |
02.10.2003 | |
Your age is 16 years, 6 months, 13 days. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment