Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a program to read your age from the console and print how old you will be after 10 years.
- using System;
- class CalculateAge
- {
- static void Main()
- {
- Console.WriteLine("Please enter your birthday:");
- Console.Write("\t Day: ");
- int day = int.Parse(Console.ReadLine());
- Console.Write("\t Month: ");
- int month = int.Parse(Console.ReadLine());
- Console.Write("\t Year: ");
- int year = int.Parse(Console.ReadLine());
- DateTime bDay = new DateTime(year, month, day);
- DateTime today = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day);
- int ageToday = today.Year - bDay.Year;
- DateTime future = new DateTime();
- if (today.Month > bDay.Month)
- {
- future = today.AddYears(10);
- }
- else if (today.Month == bDay.Month)
- {
- if (today.Day > bDay.Day)
- {
- future = today.AddYears(9);
- }
- else if(today.Day <= bDay.Day)
- {
- future = today.AddYears(10);
- }
- }
- else
- {
- future = today.AddYears(9);
- }
- int futureAge = future.Year - bDay.Year;
- Console.WriteLine("In 10 years you will be {0} years old!", futureAge);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement