Created
March 8, 2014 22:32
-
-
Save scinetic/9440022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DateTime birthDay; // Declaring variable 'birthDay' of type 'DateTime' | |
if (DateTime.TryParse(Console.ReadLine(), out birthDay)) // Getting birthdate and initializing it to 'birthDay' | |
{ | |
DateTime today = DateTime.Today; // Getting the current date | |
int age = today.Year - birthDay.Year; //Getting the age | |
if (birthDay > today.AddYears(-age)) age--; // Checking for accuracy of the age | |
Console.WriteLine(age); // Displaying the current age | |
Console.WriteLine(age + 10); // Displaying the age after 10 years | |
} | |
else | |
{ | |
Console.WriteLine("Please enter the birthday in proper format (e.g. dd.mm.yyyy)"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment