I have to write a program that reads birthday date from the console (in the format MM.DD.YYYY) and prints current age and age in 10 years.
This is one of my first codes and in my opinion it looks too lame. I believe there is a better way to write this, so I would like to ask you for suggestions on how to optimize the code.
using System;
namespace Age
{
class Age
{
static void Main()
{
string birthDayAsk;
Console.WriteLine("Date format: MM.DD.YYYY");
birthDayAsk = Console.ReadLine();
DateTime birthday = DateTime.Parse(birthDayAsk);
DateTime today = DateTime.Today;
int age = today.Year - birthday.Year;
if ((birthday.Month > today.Month) || ((birthday.Month == today.Month) && (birthday.Day > today.Day)))
{
age = age - 1;
Console.WriteLine(age);
}
else
{
Console.WriteLine(age);
}
Console.WriteLine(age + 10);
}
}
}