Advertisement
ekostadinov

C# CalculateMyAgeAfterDecade

Sep 18th, 2012
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _12.CalculateMyAge
  7. {
  8.     class CalculateMyAge
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Console.WriteLine("Please enter your year of birth!");
  13.             int birthYear = int.Parse(Console.ReadLine());
  14.             int result = (DateTime.Now.Year + 10) - birthYear;
  15.  
  16.             //we can use if loop to check for correct user input
  17.  
  18.             if (birthYear != 0 && birthYear > 1890 && birthYear < DateTime.Now.Year + 1)
  19.             {
  20.                 Console.Write("After one decade you will be {0} years old!", result);            
  21.             }
  22.             else
  23.             {
  24.                 Console.WriteLine("Incorrect input!Please try again!");
  25.             }
  26.  
  27.             Console.WriteLine();
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement