0

So, I am creating a mathematical program, it has a couple of functions, one of the function is a decimal place holder, what this is:

the user is asked how many decimal places between 1 and 5. he would like his answers to be shown for the different mathematical function.

Let’s say the user chooses the answer to be to 4 decimal places, he then sets this up and he chooses the quadratic equation solver, he is asked for A,B,C values, once it is calculated the, let say he gives inputs of 1, -8 and 15, the answer is -3 and 5. However as he had chosen his answer to be to 4 decimal places the answer should be produced as -3.0000 and 5.0000

I can not get this to work, here is my code below, can someone help me solve this, been stuck on it for a couple of days now

I have tried to round the number by the Decimal place input from the user: not working

'Decimal place rule

     Sub Accuracy()

      Line1: 
      Dim DP 
      Console.WriteLine("Please Enter the Decimial Limit between 1-5: ") 
      DP = Double.Parse(Console.ReadLine()) 

      If (DP > 5) Then 
      Console.WriteLine("Error, Decimial Limit is between 1 and 5, Please Try Again!") 
       GoTo Line1

        Else
        DP = DP
       Console.Write("Decimial Limit has been Set Succuesfully to " & DP & " Decimal Places")
        End If
         End Sub

'Quadratic Equation function

   Sub QuadraticFunction() 
    Dim a, b, c As Integer 
    Dim d, x1, x2 As Double

   line1:

   Console.WriteLine("Please Input a Non-Zero Number, A: ")
  a = Console.ReadLine()
   If (a = 0) Then
   Console.WriteLine("Error, Number must not be 0, Try Again!")
   GoTo line1
   End If
   Console.WriteLine("Please Input The Value of, B: ")
    b = Console.ReadLine()

   Console.Write("Please Input the Value of, C: ")
   c = Console.ReadLine()

   d = b * b - (4 * a * c)
    If (d = 0) Then

   Console.WriteLine("Both Roots Are Equal.")
   x1 = -b / (2.0 * a)
   x2 = x1
    x1 = Math.Round(x1, DP)
   x2 = Math.Round(x1, DP)
    Console.WriteLine("First Root, (Root1) = {0}", x1)
    Console.WriteLine("Second Root, (Root2) = {0}", x2)

   ElseIf (d > 0) Then

   Console.WriteLine("Both Roots are Real and Different")

   x1 = (-b + Math.Sqrt(d)) / (2 * a)
   x2 = (-b - Math.Sqrt(d)) / (2 * a)


   x1 = (Math.Round(x1, DP))
   x2 = (Math.Round(x2, DP))

   Console.WriteLine("First Root, (Root1) = {0}", x1)
   Console.WriteLine("Second Root, (Root2) = {0}", x2)

   Else

  Console.Write("Root are Imaginary " & "No Solution")
    End If
    End Sub
Casemiro
  • 17
  • 3

0 Answers0