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. */
- namespace _15.AgeAfter10Years
- {
- using System;
- using System.Globalization;
- using System.Threading;
- public class PrintYourAgeNowAndAfter10Years
- {
- public static void Main(string[] args)
- {
- Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
- checked
- {
- Console.WriteLine("Your Birthday must writing exactly in that format: dd.MM.yyyy !");
- Console.WriteLine("For Example: '25.03.1995'");
- Console.Write("Enter your BIRTHDAY: ");
- string inputStr = Console.ReadLine();
- string dateFormatStr = "dd.MM.yyyy";
- DateTime yourBirthday = DateTime.ParseExact(inputStr, dateFormatStr, CultureInfo.InvariantCulture);
- DateTime today = DateTime.Today;
- // Calculate difference between these 2 dates in Days and convert them in Years!
- int differenceInDays = (int)(today - yourBirthday).TotalDays;
- int daysForLeapYears = (differenceInDays / 365) / 4;
- int age = (differenceInDays - daysForLeapYears) / 365;
- Console.WriteLine("Now, you are {0} years old!", age);
- int ageAfter10Years = age + 10;
- Console.WriteLine("After 10 Years, you will be {0} years old!", ageAfter10Years);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement