Question #12696

Problem: Barney has 10 children. Please help me to create a program that would enter the age of his 10 children into an array with 10 elements.The age of his youngest child will go into the first element and so on with the age of the oldest child going into the last element. Program must then display the following:

- age of all his children from the oldest to the youngest.

-the average age

-the maximum age

-the minimum age

Thank you experts!

- age of all his children from the oldest to the youngest.

-the average age

-the maximum age

-the minimum age

Thank you experts!

Expert's answer

`Module Module1`

Sub Main()

Dim arrayofages(10) As Integer

For i

As Integer = 0 To 9

Console.Write("Enter age for children " + (i +

1).ToString() + ": ")

arrayofages(i) =

Integer.Parse(Console.ReadLine())

Next

BubbleSort(arrayofages)

Console.Write("Age

of all his children from the oldest to the youngest:" +

Environment.NewLine)

For i As Integer = 9 To 0 Step

-1

Console.Write(arrayofages(i).ToString() + "

")

Next

Console.WriteLine(Environment.NewLine + "The average age: " +

AverageAge(arrayofages).ToString())

Console.WriteLine("The maximum age: " +

MaximumAge(arrayofages).ToString())

Console.WriteLine("The minimum age: " +

MinimumAge(arrayofages).ToString())

Console.ReadLine()

End Sub

'''

<summary>

''' Sort array

''' </summary>

''' <param

name="numbers"></param>

'''

<remarks></remarks>

Private Sub BubbleSort(ByRef numbers() As

Integer)

Dim temp

Dim switch = True

While switch

switch =

False

For x = 0 To 8

If numbers(x) > numbers(x + 1) Then

temp =

numbers(x)

numbers(x) = numbers(x + 1)

numbers(x + 1) = temp

switch =

True

End If

Next

End While

End Sub

Private Function

AverageAge(ByRef numbers() As Integer) As Double

Dim average As Double =

0

Dim sum = 0

For i As Integer = 0 To 9

sum +=

numbers(i)

Next

average = sum / 10

Return average

End

Function

Private Function MaximumAge(ByRef numbers() As Integer) As

Integer

Dim max As Integer = numbers(0)

For i As Integer = 0 To 9

If

max < numbers(i) Then

max = numbers(i)

End If

Next

Return

max

End Function

Private Function MinimumAge(ByRef numbers() As Integer)

As Integer

Dim min As Integer = numbers(0)

For i As Integer = 0 To 9

If

min > numbers(i) Then

min = numbers(i)

End If

Next

Return

min

End Function

End Module

Learn more about our help with Assignments: Visual Basic

## Comments

## Leave a comment