Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Homework3
  4. {
  5.     class Program
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("Enter EGN");
  10.             string egn = Console.ReadLine();
  11.             char[] arrEgn = egn.ToCharArray();
  12.             int year = int.Parse(String.Concat(arrEgn[0], arrEgn[1]));
  13.             int month = int.Parse(String.Concat(arrEgn[2], arrEgn[3]));
  14.             int day = int.Parse(String.Concat(arrEgn[4], arrEgn[5]));
  15.             String control = arrEgn[9].ToString();
  16.  
  17.             DateTime now = DateTime.Today;
  18.  
  19.             if (month >= 41)
  20.             {
  21.                 year += 2000;
  22.                 month -= 40;
  23.             }
  24.             else if (month >= 21)
  25.             {
  26.                 year += 1800;
  27.                 month -= 20;
  28.             }
  29.             else
  30.             {
  31.                 year += 1900;
  32.             }
  33.  
  34.             DateTime birthday = new DateTime(year, month, day);
  35.             var totalDays = (now - birthday).TotalDays;
  36.             var totalYears = Math.Truncate(totalDays / 365);
  37.             var totalMonths = Math.Truncate((totalDays % 365) / 30);
  38.             var remainingDays = Math.Truncate((totalDays % 365) % 30);
  39.             Console.WriteLine("{0} years, {1} months, {2} days, control number: {3}", totalYears, totalMonths, remainingDays, control);
  40.  
  41.             Console.ReadKey();
  42.  
  43.         }
  44.  
  45.  
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement