PavelManahilov

Age After Ten Years

Aug 24th, 2015
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. using System;
  2.  
  3. class AgeAfterTenYears
  4. {
  5. static void Main()
  6. {
  7. // Input your birth date and convert it to Datetime format
  8. Console.WriteLine("Input your birth year in format: dd.MM.yyy - Example: 01.01.2001");
  9. string myBirthDateInput = Console.ReadLine();
  10. DateTime myBirthDate = DateTime.ParseExact(myBirthDateInput,"dd.MM.yyyy",null);
  11.  
  12. // Get the curent date
  13. DateTime todayDate = DateTime.Now;
  14.  
  15. // Substract your Birth year from current year, to get your current age
  16. int myAge = todayDate.Year - myBirthDate.Year;
  17.  
  18. // Check if your birthday is still to come and if it is not come yet take out one year from your age
  19. if (todayDate < myBirthDate.AddYears(myAge))
  20. {
  21. myAge--;
  22. }
  23.  
  24. // Print the results
  25. Console.WriteLine("Now: " + myAge);
  26. Console.WriteLine("After 10 years: " + (myAge + 10));
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment