static void Main(string[] args) { AgeCalculator c = new AgeCalculator(); DateTime dt; while (true) { try { Console.WriteLine("Enter a valid date: "); string input = Console.ReadLine(); if (c.ParseInput(input, out dt)) { break; } } catch (System.FormatException) { Console.WriteLine("Incorrect date format. Use dd-mm-yyyy and a VALID date."); } } Console.WriteLine("You are {0} years old!", c.CalculateAge(dt)); // let's not close the console immediatly Console.ReadLine(); }
static void Main(string[] args) { AgeCalculator AC = new AgeCalculator(); DateTime result; string naam = Console.ReadLine(); Console.Write("Hello " + naam + "\n"); Console.Write("Write your date of birth \n"); string dateBirth = Console.ReadLine(); if (AC.ParseInput(dateBirth, out result)) { Console.Write(AC.CalculateAge(result)); Console.ReadKey(); } else { Console.Write("That was not a valid input for the date of birth"); } }
static void Main(string[] args) { AgeCalculator calc = new AgeCalculator(); Console.WriteLine("Geef een datum om te berekenen (format: dd-mm-yyyy):"); Console.WriteLine("Typ 'Q' om te stoppen\n"); String input = Console.ReadLine(); while (input.ToLower() != "q") { DateTime result; if (calc.ParseInput(input, out result)) { Console.WriteLine("Je leeftijd is {0}", calc.CalculateAge(result)); Console.WriteLine("\nGeef een datum om te berekenen (format: dd-mm-yyyy):"); } else { Console.WriteLine("Ongeldige input! probeer het nogmaals (dd-mm-yyyy):"); } input = Console.ReadLine(); } }