# Array of struct and menu VB.Net Exercise - Visual Basic Programming Course

### Code

``````Imports System
Public Class exercise81
Structure points
Public x As Byte
Public y As Byte
End Structure

Private Shared Sub Main(ByVal args As String())
Dim p As points() = New points(999) {}
Dim Finish As Boolean = False
Dim countArray As Integer = 0
Dim TotalX As Integer = 0
Dim TotalY As Integer = 0

Do
Console.WriteLine("2.Display all the entered points")
Console.WriteLine("3.Calculate (and display) the average values for x and y")
Console.WriteLine("0.Exit the program")
Console.Write("Enter a number: ")
Dim respuesta As Byte = Convert.ToByte(Console.ReadLine())

Select Case respuesta
Case 1
Console.WriteLine()
Console.Write("Enter a number for point x: ")
TotalX += p(countArray).x
Console.WriteLine()
Console.Write("Enter a number for point y: ")
TotalY += p(countArray).y
Console.WriteLine()
countArray += 1
Case 2

If countArray > 0 Then

For i As Integer = 0 To countArray - 1
Console.WriteLine("Valor x{0}: {1}", i + 1, p(i).x)
Console.WriteLine("Valor y{0}: {1}", i + 1, p(i).y)
Next
Else
Console.WriteLine("No hay datos")
End If

Case 3

If countArray > 0 Then
Console.WriteLine("Average x: {0}", TotalX / countArray)
Console.WriteLine("Average y: {0}", TotalY / countArray)
Else
Console.WriteLine("No hay datos")
End If

Case 0
Finish = True
Case Else
End Select
Loop While Not Finish
End Sub
End Class``````