这是作业。有人可以帮我弄清楚我声明的错误吗?当我给 Double 时,我总是出错
This is homework. Can someone help me figure out what I have declared wrong? I keep getting an error when I give Double
Function quadratic (a As double, b As double, c As double) As Double
Dim x,y As Double
if (a = 0) then
Console.Writeline("no solution for a = 0")
else if
((b * b - 4 * a * c) <0)
Console.Writeline("no real solutions")
else
x = ((- b + Math.Sqrt(b * b - 4 * a * c)) / ( 2 * a))
y = ((- b - Math.Sqrt(b * b - 4 * a * c)) / ( 2 * a))
if (x > y) then
Console.Writeline(x)
else
Console.Writeline(y)
End if
End if
End Function
我不会为你检查你的数学:-)但是如果你改变这个:
else if
((b * b - 4 * a * c) <0)
Console.Writeline("no real solutions")
为此:
ElseIf ((b * b - 4 * a * c) < 0) Then
Console.Writeline("no real solutions")
编译运行...
Function quadratic (a As double, b As double, c As double) As Double
Dim x,y As Double
if (a = 0) then
Console.Writeline("no solution for a = 0")
else if
((b * b - 4 * a * c) <0)
Console.Writeline("no real solutions")
else
x = ((- b + Math.Sqrt(b * b - 4 * a * c)) / ( 2 * a))
y = ((- b - Math.Sqrt(b * b - 4 * a * c)) / ( 2 * a))
if (x > y) then
Console.Writeline(x)
else
Console.Writeline(y)
End if
End if
End Function
我不会为你检查你的数学:-)但是如果你改变这个:
else if
((b * b - 4 * a * c) <0)
Console.Writeline("no real solutions")
为此:
ElseIf ((b * b - 4 * a * c) < 0) Then
Console.Writeline("no real solutions")
编译运行...