gpt4 book ai didi

c# - C#变量UserInput找不到定义

转载 作者:行者123 更新时间:2023-12-03 08:12:07 24 4
gpt4 key购买 nike

double UserInput;
string y, z;
double OunceToGram, PoundToOunce, PoundToKilogram, PintToLitre, InchToCenti, MilesToInch;


OunceToGram = UserInput * 28.0; //(error is here, it cannot find UserInput)
PoundToOunce = UserInput * 16.0;
PoundToKilogram = UserInput * 0.454;
PintToLitre = UserInput * 0.568;
InchToCenti = UserInput * 2.5;
MilesToInch = UserInput * 63360.0;

int i = 0;

while (i < UserInput)
{
Console.WriteLine("");
Console.WriteLine("Please enter a unit to convert, type a num <1 to cancel");
UserInput = Convert.ToDouble(Console.ReadLine());

最佳答案

您可以解决不立即将用户输入转换为变量UserInput并检查用户是否键入常规字母来停止输入的问题

double UserInput = 0.0;  // <- You need to initialize before using it ...
.....

string stopInput = "N";
while (stopInput != "Q"))
{
Console.WriteLine("");
Console.WriteLine("Please enter a unit to convert, type 'Q' to cancel");
stopInput = Console.ReadLine();
if(stopInput == "Q")
break;
UserInput = Convert.ToDouble(stopInput);
....
}

关于c# - C#变量UserInput找不到定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36533092/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com