Skip to content

Instantly share code, notes, and snippets.

@DreamerDeLy
Created April 13, 2020 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DreamerDeLy/446991a9498939d15a01891376c7aafa to your computer and use it in GitHub Desktop.
Save DreamerDeLy/446991a9498939d15a01891376c7aafa to your computer and use it in GitHub Desktop.
Task 14 [C#]
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();
}
}
}
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