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!
1
Expert's answer
2012-08-09T07:37:34-0400
Module Module1Sub Main()Dim arrayofages(10) As IntegerFor i As Integer = 0 To 9Console.Write("Enter age for children " + (i + 1).ToString() + ": ")arrayofages(i) = Integer.Parse(Console.ReadLine())NextBubbleSort(arrayofages)Console.Write("Age of all his children from the oldest to the youngest:" + Environment.NewLine)For i As Integer = 9 To 0 Step -1Console.Write(arrayofages(i).ToString() + " ")NextConsole.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 tempDim switch = TrueWhile switchswitch = FalseFor x = 0 To 8If numbers(x) > numbers(x + 1) Thentemp = numbers(x)numbers(x) = numbers(x + 1)numbers(x + 1) = tempswitch = TrueEnd IfNextEnd WhileEnd SubPrivate Function AverageAge(ByRef numbers() As Integer) As DoubleDim average As Double = 0Dim sum = 0For i As Integer = 0 To 9sum += numbers(i)Nextaverage = sum / 10Return averageEnd FunctionPrivate Function MaximumAge(ByRef numbers() As Integer) As IntegerDim max As Integer = numbers(0)For i As Integer = 0 To 9If max < numbers(i) Thenmax = numbers(i)End IfNextReturn maxEnd FunctionPrivate Function MinimumAge(ByRef numbers() As Integer) As IntegerDim min As Integer = numbers(0)For i As Integer = 0 To 9If min > numbers(i) Thenmin = numbers(i)End IfNextReturn minEnd FunctionEnd 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 the first!
LATEST TUTORIALS
APPROVED BY CLIENTS