Advertisement
Guest User

Age After 10 Years

a guest
Oct 25th, 2014
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1.  
  2. using System;
  3.  
  4.     class Program
  5.     {
  6.     static void Main()
  7.     {
  8.         int? daysToBirthday = null;
  9.         int? MonthsToBirthday = null;
  10.         Console.WriteLine("Please Enter Your Birthday : \n");
  11.         DateTime Birthday = DateTime.Parse(Console.ReadLine()); // Get your birtday from the console
  12.         int result = (DateTime.Now.Year - Birthday.Year); // Calculate your age
  13.         Console.Clear();                        // Clear the console after geting your birthday
  14.         Console.WriteLine("Your Birthday is " + Birthday);
  15.  
  16.         // Check if your birthday month is the same as now
  17.  
  18.         if (DateTime.Now.Month == Birthday.Month) // Check if your birthday month is the same as now
  19.         {
  20.  
  21.             // If your birthday month is the same as now , check the day
  22.             if (DateTime.Now.Day < Birthday.Day)
  23.             {
  24.  
  25.                  // If your birthday is not passed , pulls one year and print the result
  26.                 result = (result - 1);                      
  27.                 daysToBirthday = Birthday.Day - DateTime.Now.Day;
  28.             }
  29.  
  30.             // Happy birthday, the day and month of birthday match exactly
  31.             if (DateTime.Now.Day == Birthday.Day)
  32.             daysToBirthday = 0;
  33.         }
  34.  
  35.             // Check if your birthday month is greater than month now
  36.  
  37.             if (DateTime.Now.Month < Birthday.Month)
  38.            {
  39.                MonthsToBirthday = Birthday.Month - DateTime.Now.Month;
  40.                if (MonthsToBirthday >= 1)
  41.                {
  42.                    Console.WriteLine("Your Birthday Is After " + (MonthsToBirthday) + " Months");
  43.                }
  44.  
  45.                 // if so remove one years and show you the result
  46.  
  47.                Console.WriteLine("Your Age Now Is : " + (result - 1));
  48.  
  49.                // Just to avoid take out 1 and then add 10
  50.                Console.WriteLine("Your Age After 10 Years Will Be : " + (result + 9));
  51.            }
  52.  
  53.            else
  54.           {
  55.  
  56.               // If your birthday month has passed just shows you the result
  57.               Console.WriteLine("Your Age Now Is : " + result);
  58.               if (daysToBirthday >= 1)
  59.                   {
  60.                   Console.WriteLine("Your Birthday Is After " + (daysToBirthday) + " Days");
  61.                   }
  62.                   if (daysToBirthday == 0)
  63.                       {
  64.                       Console.WriteLine("Your Birthday Is Today");
  65.                       }
  66.  
  67.                       // Just the result + 10 years
  68.                       Console.WriteLine("Your Age After 10 Years Will Be : " + (result + 10));
  69.            }
  70.  
  71.       }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement