Advertisement
svetlozar_kirkov

Age after ten years (Homework)

Oct 19th, 2014
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3.  
  4. namespace AgeAfterTenYears
  5. {
  6.     class AgeAfterTenYears
  7.     {
  8.         static void Main()
  9.         {
  10.             Console.Write("Enter your birthday (dd-mm-yyyy): ");
  11.             DateTime birthday = DateTime.ParseExact(Console.ReadLine(),
  12.                 "d-M-yyyy", CultureInfo.CurrentCulture);
  13.             TimeSpan diff = DateTime.Now - birthday;
  14.             int yearsOld = GetYears(diff);
  15.             Console.WriteLine("You are {0} years old. \nAfter ten years you will be {1} years old.",yearsOld,yearsOld+10);
  16.            
  17.         }
  18.         public static int GetYears(TimeSpan timespan)
  19.         {
  20.             return (int)((double)timespan.Days / 365.2425);
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement