Advertisement
ivan_yosifov

calculate_age_in_10_years

Nov 11th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. //Write a program to read your age from the console and print how old you will be after 10 years.
  2.  
  3. using System;
  4.  
  5. class CalculateAge
  6. {
  7.     static void Main()
  8.     {
  9.         Console.WriteLine("Please enter your birthday:");
  10.         Console.Write("\t Day: ");
  11.         int day = int.Parse(Console.ReadLine());
  12.         Console.Write("\t Month: ");
  13.         int month = int.Parse(Console.ReadLine());
  14.         Console.Write("\t Year: ");
  15.         int year = int.Parse(Console.ReadLine());
  16.  
  17.         DateTime bDay = new DateTime(year, month, day);
  18.        
  19.        
  20.         DateTime today = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day);
  21.  
  22.         int ageToday = today.Year - bDay.Year;
  23.  
  24.         DateTime future = new DateTime();
  25.  
  26.         if (today.Month > bDay.Month)
  27.         {
  28.             future = today.AddYears(10);
  29.         }
  30.         else if (today.Month == bDay.Month)
  31.         {
  32.             if (today.Day > bDay.Day)
  33.             {
  34.                 future = today.AddYears(9);
  35.             }
  36.             else if(today.Day <= bDay.Day)
  37.             {
  38.                 future = today.AddYears(10);
  39.             }
  40.         }
  41.         else
  42.         {
  43.             future = today.AddYears(9);
  44.         }
  45.  
  46.         int futureAge = future.Year - bDay.Year;
  47.         Console.WriteLine("In 10 years you will be {0} years old!", futureAge);
  48.        
  49.  
  50.        
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement