Программа работает правильно в том смысле, что она получает пользовательский ввод, но результаты не отображаются.
Попытка рассчитать расстояние между двумя точками с использованием массивов и двух функций. Две точки берутся из пользовательского ввода. Программа работает правильно в том смысле, что она получает пользовательский ввод, но результаты не отображаются.
Модуль Модуль1
Sub Main()
Dim myPointA(3, 2) As Double
Dim myPointB(3, 2) As Double
Console.WriteLine("Enter 3 coordinate points for A: ")
myPointA = UserInput()
Console.WriteLine("Enter 3 coordinate points for B")
myPointB = UserInput()
DistResult(myPointA, myPointB)
End Sub
Function UserInput() As Double(,)
Dim point(3, 2) As Double
For i As Integer = 0 To 2
Console.Write("Enter the value of x coordinate for point " & (i + 1) & " : ")
point(i, 0) = Convert.ToDouble(Console.ReadLine())
Console.Write("Enter the value of y coordinate for point " & (i + 1) & " : ")
point(i, 1) = Convert.ToDouble(Console.ReadLine())
Console.WriteLine()
Next
Return point
End Function
Sub DistResult(myPointA As Double(,), myPointB As Double(,))
Dim Distance As Double
For i As Integer = 0 To 2
Distance = findDistance(myPointA(i, 0), myPointA(i, 1), myPointB(i, 0), myPointB(i, 1))
Console.WriteLine("A(" & myPointA(i, 0) & "," & myPointA(i, 1) & ") B(" & myPointB(i, 0) & "," & myPointB(i, 1) &
") Distance = " & Math.Round(Distance, 2))
Next
End Sub
Function findDistance(x1 As Double, y1 As Double, x2 As Double, y2 As Double) As Double
Dim distance As Double
distance = Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2))
Return distance
End Function
Конечный модуль