Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class AgeAfter10Y
- {
- static void Main()
- {
- string input;
- int ageYears, ageMonths, futureAge, monthsDiff, daysDiff;
- ageMonths = 0;
- DateTime currentYear, bdate;
- currentYear = DateTime.Now;
- Console.WriteLine("This program will precisely calculate your age in years after 10 years");
- Console.Write("Please enter your birthday in the format (dd-mm-yyyy): ");
- input = Console.ReadLine();
- bdate = Convert.ToDateTime(input);
- monthsDiff = currentYear.Month - bdate.Month;
- daysDiff = currentYear.Day - bdate.Day;
- ageYears = currentYear.Year - bdate.Year;
- //The next code will check if you've had your birthday this year or not and substract 1y from your age if you haven't.
- if (bdate.DayOfYear == DateTime.Now.DayOfYear)
- {
- Console.WriteLine("Happy Birthday!");
- }
- else if ((monthsDiff == 0 && daysDiff < 0) || (monthsDiff < 0))
- {
- ageYears = ageYears - 1;
- ageMonths = monthsDiff + 12;
- }
- else
- {
- ageYears = ageYears + 1;
- }
- futureAge = ageYears + 10;
- Console.WriteLine("Your age is now is {0} years and {1} months", ageYears, ageMonths);
- Console.WriteLine("Your age in 10 years will be {0} years and {1} months", futureAge, ageMonths);
- Console.WriteLine("Have a nice day!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment