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 he would like his answers to be shown for the different mathematical solvers, so example is if he says 3 then my answer for another function e.g 1+1 would equal 2.000
They are asked a range between 1 and 5, I have the code for this but do not know how to implement it for the answer of the functions
'Decimal place
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
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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…