![](/img/trans.png)
[英]C# Console Application where user enters resource and is told what Junk is required
[英]Trying to make it in c# where the user enters their age and it tells them what year they were born in
这是我到目前为止的代码,我现在被困住了。
static void Main(string[] args)
{
int age = 0;
DateTime now = DateTime.Today;
Console.WriteLine("What is your age?");
age = Convert.ToInt32(Console.ReadLine());
}
一个简单的方法是创建一个字符串变量,它是一个 console.readline,将字符串转换为 int(age),然后从当前年份中减去年龄,这个等式的结果将是他们出生的年份。 然而,这仍然不是完美的,好像你还没有过生日,但它可能是一年的假期。
String stringAge = Console.ReadLine();
int age = Convert.ToInt32(stringAge);
//year is 2021
int result = age-2021;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.