-11 c# variables local-variables
我有以下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();
Run Code Online (Sandbox Code Playgroud)
当我尝试调试程序时,我收到此消息"使用未分配的局部变量'回答'(CS0165)",我的问题是如何解决它,问题出在哪里?
答案永远不会被初始化.
double eps=0.1, low=1, y0=0, x=0, y=0, high=0, muchlat=0, answer=0, ribua=0;
Run Code Online (Sandbox Code Playgroud)