Advertisement
TodorovH

AgeAfter10Years

Mar 9th, 2014
830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. using System;
  2.  
  3. class AgeAfter10Years
  4. {
  5. static void Main()
  6. {
  7. Console.WriteLine();
  8. Console.Write("Write your Birthday: ");
  9. string userBirthday = Console.ReadLine();
  10. DateTime birthday;
  11. int userYearOfBirth;
  12. int userAge = 0;
  13. int ageAfter10Years = 0;
  14. int presentDay = DateTime.Now.Day;
  15. int presentMonth = DateTime.Now.Month;
  16. int today = DateTime.Now.Year;
  17. bool properDate = DateTime.TryParse(userBirthday, out birthday);
  18. if (properDate)
  19. {
  20. string userMonth = userBirthday;
  21. userBirthday = userBirthday.Substring(0, 2);
  22. userMonth = userMonth.Substring(3, 2);
  23. int dayOfBirth = int.Parse(userBirthday);
  24. int monthOfBirth = int.Parse(userMonth);
  25. userYearOfBirth = birthday.Year;
  26. if (presentMonth < monthOfBirth)
  27. {
  28. userAge = today - userYearOfBirth - 1;
  29. ageAfter10Years = userAge + 10;
  30. }
  31. if ((presentDay >= dayOfBirth) && (presentMonth >= monthOfBirth))
  32. {
  33. userAge = today - userYearOfBirth;
  34. ageAfter10Years = userAge + 10;
  35. }
  36. if ((presentDay < dayOfBirth) && (presentMonth >= monthOfBirth))
  37. {
  38. userAge = today - userYearOfBirth - 1;
  39. ageAfter10Years = userAge + 10;
  40. }
  41. Console.WriteLine();
  42. Console.WriteLine("You are {0} Years old!", userAge);
  43. Console.WriteLine();
  44. Console.WriteLine("Your age after 10 Years going to be {0} Years!", ageAfter10Years);
  45. Console.WriteLine();
  46. }
  47. else
  48. {
  49. Console.WriteLine();
  50. Console.WriteLine("Incorrect age format!");
  51. Console.WriteLine();
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement