Advertisement
G_Burlakova

AgeAfterTenYears

Mar 23rd, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class AgeAfterTenYears
  8. {
  9.     static void Main(string[] args)
  10.     {
  11.         Console.Write("Enter your birthday: ");
  12.         string birsthdayStr = Console.ReadLine();
  13.         DateTime birthday;
  14.         int currentYear = DateTime.Now.Year;
  15.         int yearOfBirth;
  16.         int ageNow;
  17.         int ageAfterTenYears;
  18.         bool birthdayCorrectFormat = DateTime.TryParse(birsthdayStr, out birthday);
  19.         if (birthdayCorrectFormat)
  20.         {
  21.             yearOfBirth = birthday.Year;
  22.             DateTime birthdayThisYeas = new DateTime(currentYear, birthday.Month, birthday.Day);
  23.             if (birthdayThisYeas > DateTime.Today)
  24.             {
  25.                 ageNow = (currentYear - yearOfBirth) - 1;
  26.             }
  27.             else
  28.             {
  29.                 ageNow = currentYear - yearOfBirth;
  30.             }
  31.             ageAfterTenYears = ageNow + 10;
  32.             Console.WriteLine("Your age now: {0}. Your age after 10 years: {1}", ageNow, ageAfterTenYears);
  33.         }
  34.         else
  35.         {
  36.             Console.WriteLine("Wrong format of birthday.");
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement