First off, the way you are doing that is a ad idea - you have no verification at all of the user input, so if I enter "Hello" for my age your app will crash.
DOn't use
Convert
methods for user input - they always throw an exception if the conversion fails - use the
TryParse
methods instead.
Secondly, age, is a complication thing: not only does it potentially vary from day to day, but it can have legal implications - what you can't do today without being arrested you may be able to tomorrow, and vice versa. Just asking for a year is not enough!
Thirdly, just getting a year doesn't help much unless you validate it: if I enter "999" or "3" or "99" what should your app do with them?
So instead of that, read the whole birth date from the user and convert it to a DateTime value:
DateTime dob;
while (true)
{
Console.Write("Please enter your date of birth: ");
string inp = Console.ReadLine();
if (DateTime.TryParse(inp, out dob)) break;
Console,WriteLine($"\"{inp}\" is not a valid date!");
}
Then you can use
DateTime.Now
to work out the Age.
This may help, but I'd suggest you try to get your version working before you go near it:
Working with Age: it's not the same as a TimeSpan![
^]