ellapt

1.12.AgeInTenYears

Dec 18th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. using System;
  2.  
  3. class AgeIn10Years
  4. {
  5. static void Main()
  6. {
  7. DateTime birthDate = new DateTime(); // your birth date
  8. DateTime dateInTenYears = DateTime.Now.AddYears(10); // the date 10 years after now
  9.  
  10. Console.Write("Please, enter your birth date: "); // enter your birth date from the console,
  11. // then check if valid (assume the eldest person on Earth was 132 years old:)
  12.  
  13. if (DateTime.TryParse(Console.ReadLine(), out birthDate) && birthDate.Year < DateTime.Now.Year && birthDate.Year >= 1880)
  14. {
  15. // if data input was correct, then compute your age in 10 years and write it at the console:
  16. int ageInTenYears = dateInTenYears.Year - birthDate.Year;
  17. Console.WriteLine("Ten years later you will be " + ageInTenYears); //
  18. }
  19. else
  20. {
  21. // wrong input - illegal date, or birth date >= now, or you seem to be an ancient person :)
  22. Console.WriteLine("Sorry, wrong input! Try again!");
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment