Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class AgeAfterXYears
- {
- static void Main()
- {
- string inputDate;
- Console.Write("Please write in your date in this manner (e.g. 19.04.1991): ");
- inputDate = Console.ReadLine();
- DateTime dt;
- try
- {
- dt = Convert.ToDateTime(inputDate);
- }
- catch
- {
- var temp = "1.1.1900";
- dt = Convert.ToDateTime(temp);
- Console.WriteLine("\nWrong date!");
- }
- var theBd = new DateTime(dt.Year, dt.Month, dt.Day);
- Console.WriteLine("\nAssuming you are born: " + dt.Month + "." + dt.Day+"."+dt.Year);
- var nowYears = (DateTime.Now - theBd).TotalDays / 365.2425;
- var incrYears = 10; //you could change if you'd like to say in how many years
- var afterXYears = incrYears + nowYears;
- if (nowYears < 0)
- {
- Console.WriteLine("\nNow: You are not born yet, please wait " + nowYears * (-1) + " years.");
- }
- else
- {
- Console.WriteLine("\nNow: You are exactly " + nowYears + " years old!");
- }
- if (afterXYears < 0)
- {
- Console.WriteLine("\nAfter " + incrYears + " years you will still not be born! Please wait another " + afterXYears * (-1));
- }
- else
- {
- Console.WriteLine("\nAfter " + incrYears + " years you would be exactly " + afterXYears + " years old!");
- }
- //exit from the console
- Console.WriteLine("\nPlease press any key to continue");
- Console.ReadKey();
- Console.Clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment