Advertisement
Guest User

My age after 10 years

a guest
Jan 30th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. // Write a program to read your birthday from the console and print how old you are now and how old you will be after 10 years.
  3. class AgeAfter10Years
  4. {
  5.     static void Main()
  6.     {
  7.         Console.WriteLine("Please enter your birthday (ex. DD/MM/YY): ");
  8.         DateTime birthDay = new DateTime();
  9.         birthDay = DateTime.Parse(Console.ReadLine());
  10.         DateTime currentDay = DateTime.Now;
  11.         int myAge = (DateTime.Now.Year - birthDay.Year);
  12.         if (birthDay.Year > currentDay.Year || birthDay.Year == currentDay.Year)
  13.         {
  14.             Console.WriteLine("You are not born!");
  15.         }
  16.         else if (currentDay.DayOfYear < birthDay.DayOfYear)
  17.         {
  18.             myAge--;
  19.             Console.WriteLine("After 10 years you will be {0} years old", myAge + 10);
  20.         }
  21.         else if (birthDay.DayOfYear == currentDay.DayOfYear)
  22.         {
  23.             Console.WriteLine("After 10 years you will be {0} years old", myAge + 10);
  24.             Console.WriteLine("Happy birthday!");
  25.         }
  26.         else
  27.         {
  28.             Console.WriteLine("After 10 years you will be {0} years old.", myAge + 10);
  29.         }
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement