Advertisement
AnitaN

01.Intro-Programming-Homework/15.2.Date-After-10-Years-Varia

Mar 9th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. //Problem 15.* Age after 10 Years
  2. //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.
  3.  
  4. using System;
  5.  
  6. class DateAfter10YearsVariant
  7. {
  8.     // VARIANT
  9.     static void Main()
  10.     {
  11.         // using DateTime and its methods AddYears() for adding years to the result and Substract() -> for substract birth year and current year
  12.         Console.Write("Enter your birthday in format(dd.mm.yyyy): ");
  13.         DateTime yourBirthday = DateTime.Parse(Console.ReadLine());
  14.         var result = DateTime.Today.Subtract(yourBirthday).Ticks;
  15.         Console.WriteLine("Now you are {0} years old.", new DateTime(result).Year - 1);
  16.         Console.WriteLine("After 10 years you will be {0} years old.", new DateTime(result).AddYears(10).Year - 1);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement