Advertisement
Ludmil

Intro C# Problem 15.* Age after 10 Years

Mar 18th, 2014
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2. /*Problem 15.   * Age after 10 YearsWrite a program to read your birthday from the console and
  3.  * print how old you are now and how old you will be after 10 years.*/
  4. // Age afret 10 year formard -> int yourage; yourage+10 :)
  5. // not the case if you take day and month.
  6. class Program
  7. {
  8.     static void Main()
  9.     {
  10.         //http://www.dotnetperls.com/time
  11.         DateTime dateBirth = DateTime.Parse("20/02/87"); // dd/mm/yy // you can change manualy
  12.         DateTime today = DateTime.Now;
  13.         DateTime futurAge = new DateTime();
  14.         int ageAfter = 10; // calculate our age after Number of years // you can change manualy
  15.         int age=0;
  16.  
  17.         if (today.Month > dateBirth.Month)
  18.         {
  19.             age = today.Year - dateBirth.Year;
  20.             futurAge = today.AddYears(ageAfter);
  21.         }
  22.         else if (today.Month == dateBirth.Month)
  23.         {
  24.             if (today.Day > dateBirth.Day)
  25.             {
  26.                 age = (today.Year - dateBirth.Year) - 1;
  27.                 futurAge = today.AddYears(ageAfter - 1);//stil haven get there:)
  28.             }
  29.             else if (today.Day <= dateBirth.Day)
  30.             {
  31.                 futurAge = today.AddYears(ageAfter);
  32.                 age = (today.Year - dateBirth.Year) - 1;
  33.             }
  34.         }
  35.         else if (today.Month < dateBirth.Month)
  36.         {
  37.             futurAge = today.AddYears(ageAfter - 1);// just befor yout b day:)
  38.             age = (today.Year - dateBirth.Year) - 1;
  39.         }
  40.         Console.WriteLine(age);
  41.         int futureAge = futurAge.Year - dateBirth.Year;
  42.         Console.WriteLine(futureAge);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement