I have madewritten an age calculator that takes a birth datebirthDate as input.
I'd like a general review of this. I'mI'm especially concerned about the message variable and the lines after the try-/catch statement.
namespace Age { class Program { static void Main(string[] args) { while (true) { try { Console.Write("Enter your birtdate: "); DateTime birthDate = DateTime.Parse(Console.ReadLine()); int Days = (DateTime.Now.Year * 365 + DateTime.Now.DayOfYear) - (birthDate.Year * 365 + birthDate.DayOfYear); int Years = Days / 365; string message = (Days >= 365) ? "Your age: " + Years + " years" : "Your age: " + Days + " days"; Console.WriteLine(message); } catch { Console.WriteLine("You have entered an invalid date.\n"); } Console.WriteLine("Exit? (y/n)"); string userValue = Console.ReadLine(); if (userValue == "y") { Environment.Exit(0); } } } } }