67 172
Assignments Done
99,3%
Successfully Done
In November 2018

Answer to Question #12696 in Visual Basic for Melody

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!
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions