Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class AgeAfterTenYears
- {
- static void Main()
- {
- Console.WriteLine("Enter 'Year' of birthday, use format yyyy: ");
- string checkAge = Console.ReadLine();
- int age;
- bool parseAge = Int32.TryParse(checkAge, out age);
- Console.WriteLine("Enter 'Month' of birthday, use format MM: ");
- string checkMonth = Console.ReadLine();
- int month;
- bool parseMonth = Int32.TryParse(checkMonth, out month);
- Console.WriteLine("Enter 'Day' of birthday, use format dd: ");
- string checkDate = Console.ReadLine();
- int day;
- bool parseDate = Int32.TryParse(checkDate, out day);
- if (parseAge && parseDate && parseMonth == false)
- {
- Console.WriteLine(" Enter Integer Value! \n");
- }
- else if (month > 12 || month <= 0)
- {
- Console.WriteLine(" Enter a valid number for month --> from 1 to 12 \n");
- }
- else if (day > 31 || day <= 0)
- {
- Console.WriteLine(" Enter a valid number for day --> from 1 to 31 \n");
- }
- else
- {
- DateTime birth = new DateTime(age, month, day);
- Console.WriteLine(" Birthdate: {0:d} \n", birth);
- DateTime today = DateTime.Now;
- TimeSpan span = today - birth;
- DateTime ageNow = DateTime.MinValue + span;
- int years = ageNow.Year - 1;
- int months = ageNow.Month - 1;
- int days = ageNow.Day - 1;
- if (years >= 70)
- {
- Console.WriteLine(" You are too Old, Go take a Break! \n");
- }
- else if (years <= 10)
- {
- Console.WriteLine(" You are too young to play with computer! \n");
- }
- else
- {
- Console.Write("Now you are: {0} years, {1} months, {2} days old. \n\n", years, months, days);
- int yearsAfter = years + 10;
- Console.Write("After 10 years you will be: {0} years, {1} months, {2} days old. \n\n", yearsAfter, months, days);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement