我這下面的C#代碼:修復代碼在C#
double eps=0.1, low=1, y0=0, x, y, high, muchlat, answer, ribua;
Console.WriteLine("Enter x");
x = double.Parse(Console.ReadLine());
high = y = x;
muchlat = Math.Abs(y - y0) ;
if (x < 0)
{
Console.WriteLine("X can't be less than zero, press any key to exit");
}
else if (muchlat > eps)
{
while (muchlat > eps)
{
Console.WriteLine(y);
y0 = y;
y = (high + low) /2;
ribua = Math.Pow(y,2);
if (ribua == x)
{
answer = x;
}
else if (ribua > x)
{
high =y;
}
else if (ribua < x)
{
low =y;
}
else if (muchlat < eps)
{
answer = y;
break;
}
}
}
Console.WriteLine(answer);
Console.ReadLine();
當我嘗試調試程序時,我得到這個消息 「未分配的局部變量‘答案’的使用(CS0165)」,我問題是我該如何解決它,問題在哪裏?
在使用它之前,爲變量'answer'指定一個值。 – Matthew
請在下一次嘗試搜索錯誤(CS0165)之前提出問題...並使樣本更小...甚至比小...更小的兩行應該已經足以解決此問題。 –