Advertisement
GogoK

DateTame_training

Jan 27th, 2015
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. using System;
  2.  
  3. class AgeAfterTenYears
  4. {
  5.     static void Main()
  6.     {
  7.         Console.WriteLine("Enter 'Year' of birthday, use format yyyy: ");
  8.         string checkAge = Console.ReadLine();
  9.         int age;
  10.         bool parseAge = Int32.TryParse(checkAge, out age);
  11.  
  12.         Console.WriteLine("Enter 'Month' of birthday, use format MM: ");
  13.         string checkMonth = Console.ReadLine();
  14.         int month;
  15.         bool parseMonth = Int32.TryParse(checkMonth, out month);
  16.  
  17.         Console.WriteLine("Enter 'Day' of birthday, use format dd: ");
  18.         string checkDate = Console.ReadLine();
  19.         int day;
  20.         bool parseDate = Int32.TryParse(checkDate, out day);
  21.  
  22.         if (parseAge && parseDate && parseMonth == false)
  23.         {
  24.             Console.WriteLine("             Enter Integer Value! \n");
  25.         }
  26.         else if (month > 12 || month <= 0)
  27.         {
  28.             Console.WriteLine("             Enter a valid number for month --> from 1 to 12   \n");
  29.         }
  30.  
  31.         else if (day > 31 || day <= 0)
  32.         {
  33.             Console.WriteLine("             Enter a valid number for day --> from 1 to 31   \n");
  34.         }
  35.  
  36.         else
  37.         {
  38.             DateTime birth = new DateTime(age, month, day);
  39.             Console.WriteLine("             Birthdate:        {0:d}     \n", birth);
  40.  
  41.             DateTime today = DateTime.Now;
  42.             TimeSpan span = today - birth;
  43.             DateTime ageNow = DateTime.MinValue + span;
  44.  
  45.             int years = ageNow.Year - 1;
  46.             int months = ageNow.Month - 1;
  47.             int days = ageNow.Day - 1;
  48.  
  49.             if (years >= 70)
  50.             {
  51.                 Console.WriteLine("         You are too Old, Go take a Break!   \n");
  52.             }
  53.             else if (years <= 10)
  54.             {
  55.                 Console.WriteLine("         You are too young to play with computer!    \n");
  56.             }
  57.             else
  58.             {
  59.                 Console.Write("Now you are:                     {0} years, {1} months, {2} days old. \n\n", years, months, days);
  60.  
  61.                 int yearsAfter = years + 10;
  62.                 Console.Write("After 10 years you will be:      {0} years, {1} months, {2} days old. \n\n", yearsAfter, months, days);
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement