Answer to Question #3786 in Visual Basic for BoB

Question #3786
Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and the display the following data:

• The lowest number in the array
• The highest number in the array
• The total of the numbers in the array
• The average of the numbers in the array
1
Expert's answer
2011-08-01T15:43:28-0400
Module Module1
Private array(20) As Integer

Sub Main()
& Console.WriteLine("Enter 20 numbers:")
& For i As Integer = 0 To 19
array(i) = Console.ReadLine()
& Next
& Console.WriteLine("The lowest number in the array: " + Lowestnumberinthearray().ToString())
& Console.WriteLine("The highest number in the array: " + Highestnumberinthearray().ToString())
& Console.WriteLine("The total of the numbers in the array: " + Totalofthenumbers().ToString())
& Console.WriteLine("The average of the numbers in the array: " + Averageofthenumbers().ToString())
& Console.ReadLine()
End Sub
& #039;'' <summary>
& #039;'' Find the highest number in the array
& #039;'' </summary>
& #039;'' <returns></returns>
& #039;'' <remarks></remarks>
Private Function Highestnumberinthearray()
& Dim low As Integer = array(0)
& For i As Integer = 0 To 19
If low < array(i) Then
low = array(i)
End If
& Next
& Return low
End Function
& #039;'' <summary>
& #039;'' Find the lowest number in the array
& #039;'' </summary>
& #039;'' <returns></returns>
& #039;'' <remarks></remarks>
Private Function Lowestnumberinthearray()
& Dim low As Integer = array(0)
& For i As Integer = 0 To 19
If low > array(i) Then
low = array(i)
End If
& Next
& Return low
End Function
& #039;'' <summary>
& #039;'' Total
& #039;'' </summary>
& #039;'' <returns></returns>
& #039;'' <remarks></remarks>
Private Function Totalofthenumbers()
& Dim totalnumber As Integer = 0
& For i As Integer = 0 To 19
totalnumber += array(i)
& Next
& Return totalnumber
End Function
& #039;'' <summary>
& #039;'' Avarage
& #039;'' </summary>
& #039;'' <returns></returns>
& #039;'' <remarks></remarks>
Private Function Averageofthenumbers()
& Dim Averagenumber As Integer = 0
& For i As Integer = 0 To 19
Averagenumber += array(i)
& Next
& Return Averagenumber / 20
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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS