![](/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.