syssboxx

Calculate Age after 10 years

May 29th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. //Write a program to read your age from the console and print how old you will be after 10 years.
  2.  
  3. using System;
  4.  
  5.  
  6. class ReadAgeReturnAfter10Years
  7. {
  8.     static void Main()
  9.     {
  10.         Console.WriteLine("Enter your date of birthday in format 'dd mm yyyy' :");
  11.         DateTime inputDate = DateTime.Parse(Console.ReadLine());
  12.        
  13.         TimeSpan tsAgesNow = DateTime.Today - inputDate;
  14.         DateTime agesNow = DateTime.MinValue; //initialise to 01 01 0001
  15.         agesNow = agesNow.Add(tsAgesNow);
  16.         Console.WriteLine("You are {0} years old", agesNow.Year - 1); //substract 1 year, because initial year is 0001
  17.  
  18.         DateTime after10 = agesNow.AddYears(10);
  19.         Console.WriteLine("Your age after 10 years will be {0}.",after10.Year - 1); //substract 1 year, because initial year is 0001
  20.        
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment