BreeA BreeA - 6 months ago 14
Vb.net Question

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

Answer

I am not going to check your math for you :-) but if you change this:

else if 
  ((b * b - 4 * a * c) <0)
  Console.Writeline("no real solutions")

To this:

ElseIf ((b * b - 4 * a * c) < 0) Then
  Console.Writeline("no real solutions")

It compiles and runs...

Comments