Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a program to read your birthday from the console and print how old you are now and how old you will be after 10 years.
- using System;
- class AgeAfter10Years
- {
- static void Main()
- {
- 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)");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement