THIS MI CLASS

Public Class Formula
    Private a As Integer
    Private b As Integer
    Private c As Integer


    Public Sub seta(ByVal x As Integer)
        a = x
    End Sub
    Public Sub setb(ByVal y As Integer)
        b = y
    End Sub
    Public Sub setc(ByVal z As Integer)
        c = z
    End Sub



    Public Function formucuadramas() As Integer


        Return -b + System.Math.Sqrt(b ^ 2 - (-4 * (a * c))) / 2 * (a)

    End Function
    Public Function formucuadramenos() As Integer

        Return -b - System.Math.Sqrt(b ^ 2 - (-4 * (a * c))) / 2 * (a)

    End Function



End Class

THIS MI INTERFACE

Module Module1

    Sub Main()
    
       
        Dim nuevo As New Formula
        nuevo.seta(1)
        nuevo.setb(2)
        nuevo.setc(-8)



        Dim respuestax1 As Integer = nuevo.formucuadramas()
        Console.WriteLine("X =")
        Console.WriteLine(respuestax1)


        Dim respuestax2 As Integer = nuevo.formucuadramenos()
        Console.WriteLine("X =")
        Console.WriteLine(respuestax2)











    End Sub

End Module

The problem is if I put a negative number like -8 in the variable the exception is activate...just work with positive number...how can I use negative number in this program??

Hi,
We cannot find the square root for negative number. Thus System.Math.Sqrt() raises OverFlowException

You are trying to FInd the Roots of an Quadratic Equation. Am I right?

To find Quadratic Equation
  > First Find Discriminant ((B * B) -  (4 * A * C) ) 
  > Then Check it Positive or Negative 
  > If Positive then Find Sqrt (These roots are real in particular If it is zero the Roots are same)
  > Else Make it To Positive by multiplying -1 (These roots are imaginary root)
  > Then find Sqrt 
  > Finally Find the Roots 
using (-b + Sqrt( Discriminant ))  / 2 * A
and 
(-b - Sqrt( Discriminant ))  / 2 * A

Note
Use parenthesis for correct result.

This question has already been answered. Start a new discussion instead.