Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Problem 15: 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()
- {
- Console.WriteLine("Enter your birth date(DD.MM.YYYY)");
- //Date time converts a string in actual date
- DateTime yourBirthDate = DateTime.Parse(Console.ReadLine());
- DateTime timeNow = DateTime.Today;
- //takes ruffly your current age now
- int currentAge = timeNow.Year - yourBirthDate.Year;
- //checks wich month and day you are born and adds the years you will be on this date
- if (timeNow.Month <= yourBirthDate.Month && timeNow.Day <= yourBirthDate.Day)
- {
- Console.WriteLine("After 10 years you will be {0}", currentAge + 9);
- }
- else
- {
- Console.WriteLine("After 10 years you will be {0}", currentAge + 10);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement