Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class AgeAfterTenYears
- {
- static void Main(string[] args)
- {
- Console.Write("Enter your birthday: ");
- string birsthdayStr = Console.ReadLine();
- DateTime birthday;
- int currentYear = DateTime.Now.Year;
- int yearOfBirth;
- int ageNow;
- int ageAfterTenYears;
- bool birthdayCorrectFormat = DateTime.TryParse(birsthdayStr, out birthday);
- if (birthdayCorrectFormat)
- {
- yearOfBirth = birthday.Year;
- DateTime birthdayThisYeas = new DateTime(currentYear, birthday.Month, birthday.Day);
- if (birthdayThisYeas > DateTime.Today)
- {
- ageNow = (currentYear - yearOfBirth) - 1;
- }
- else
- {
- ageNow = currentYear - yearOfBirth;
- }
- ageAfterTenYears = ageNow + 10;
- Console.WriteLine("Your age now: {0}. Your age after 10 years: {1}", ageNow, ageAfterTenYears);
- }
- else
- {
- Console.WriteLine("Wrong format of birthday.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement