Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class AgeAfterTenYears
- {
- static void Main()
- {
- // Input your birth date and convert it to Datetime format
- Console.WriteLine("Input your birth year in format: dd.MM.yyy - Example: 01.01.2001");
- string myBirthDateInput = Console.ReadLine();
- DateTime myBirthDate = DateTime.ParseExact(myBirthDateInput,"dd.MM.yyyy",null);
- // Get the curent date
- DateTime todayDate = DateTime.Now;
- // Substract your Birth year from current year, to get your current age
- int myAge = todayDate.Year - myBirthDate.Year;
- // Check if your birthday is still to come and if it is not come yet take out one year from your age
- if (todayDate < myBirthDate.AddYears(myAge))
- {
- myAge--;
- }
- // Print the results
- Console.WriteLine("Now: " + myAge);
- Console.WriteLine("After 10 years: " + (myAge + 10));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment