Advertisement
dimipan80

1.CalculateYourAgeNow_AndAfter10Years

Jun 1st, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. /* Write a program to read your birthday from the console and print
  2.  * how old you are now and how old you will be after 10 years. */
  3.  
  4. namespace _15.AgeAfter10Years
  5. {
  6.     using System;
  7.     using System.Globalization;
  8.     using System.Threading;
  9.  
  10.     public class PrintYourAgeNowAndAfter10Years
  11.     {
  12.         public static void Main(string[] args)
  13.         {
  14.             Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  15.             checked
  16.             {
  17.                 Console.WriteLine("Your Birthday must writing exactly in that format: dd.MM.yyyy !");
  18.                 Console.WriteLine("For Example: '25.03.1995'");
  19.                 Console.Write("Enter your BIRTHDAY: ");
  20.                 string inputStr = Console.ReadLine();
  21.                 string dateFormatStr = "dd.MM.yyyy";
  22.                 DateTime yourBirthday = DateTime.ParseExact(inputStr, dateFormatStr, CultureInfo.InvariantCulture);
  23.                 DateTime today = DateTime.Today;
  24.  
  25.                 // Calculate difference between these 2 dates in Days and convert them in Years!
  26.                 int differenceInDays = (int)(today - yourBirthday).TotalDays;
  27.                 int daysForLeapYears = (differenceInDays / 365) / 4;
  28.                 int age = (differenceInDays - daysForLeapYears) / 365;
  29.  
  30.                 Console.WriteLine("Now, you are {0} years old!", age);
  31.                 int ageAfter10Years = age + 10;
  32.                 Console.WriteLine("After 10 Years, you will be {0} years old!", ageAfter10Years);
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement