Reputation: 21
Heres the code I have so far and I'm stuck at the moment.
static void Main(string[] args)
{
int age = 0;
DateTime now = DateTime.Today;
Console.WriteLine("What is your age?");
age = Convert.ToInt32(Console.ReadLine());
}
Upvotes: 1
Views: 387
Reputation: 23
An easy way to do this would to create a string variable that is a console.readline, convert the string to and int(age), and subtract age from the current year, the result of this equation will be the year they were born. However this is still not perfect as if you have not had your birthday yet it could be a year off.
String stringAge = Console.ReadLine();
int age = Convert.ToInt32(stringAge);
//year is 2021
int result = age-2021;
Upvotes: 1