Advertisement
G_Burlakova

AgeAfterTenYears

Mar 8th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.     class Program
  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.                 ageNow = currentYear - yearOfBirth;
  23.                 ageAfterTenYears = ageNow + 10;
  24.                 Console.WriteLine("Your age after 10 years: {0}", ageAfterTenYears);
  25.             }
  26.             else
  27.             {
  28.                 Console.WriteLine("Wrong format of birthday.");
  29.             }
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement