encho253

15.Age

Oct 12th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Text.RegularExpressions;
  4.  
  5. /// <summary>
  6. /// Write a program that reads your birthday(in the format MM.DD.YYYY) from the console and prints
  7. /// on the console how old you are you now and how old will you be after 10 years.
  8. /// </summary>
  9. class Age
  10. {
  11.     /// <summary>
  12.     /// Defines the entry point of the application.
  13.     /// </summary>
  14.     static void Main()
  15.     {
  16.         string date = Console.ReadLine();
  17.         string format = "MM.dd.yyyy";
  18.         int afterTenYears = 0;
  19.         int ageNow = 0;
  20.  
  21.         DateTime birhtdate = DateTime.ParseExact(date, format, CultureInfo.InvariantCulture);
  22.  
  23.         ageNow = DateTime.Today.Year - birhtdate.Year;
  24.         afterTenYears = DateTime.Today.Year - birhtdate.Year + 10;    
  25.  
  26.         if (DateTime.Today.Day < birhtdate.Day &&
  27.             DateTime.Today.Month <= birhtdate.Month &&
  28.             birhtdate.Year <= DateTime.Today.Year)
  29.         {
  30.             Console.WriteLine(ageNow - 1);
  31.             Console.WriteLine(afterTenYears - 1);
  32.         }
  33.         else if (birhtdate.Year <= DateTime.Today.Year)
  34.         {
  35.             Console.WriteLine(ageNow);
  36.             Console.WriteLine(afterTenYears);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment