Find the average of up to 500 numbers using an array
Find the average of up to 500 numbers using an array
API Declarations
Private GetFlag As Boolean
Rate Find the average of up to 500 numbers using an array
(1(1 Vote))
'just keep the default names.
Private Sub Command1_Click()
Call Average(GetFlag)
End Sub
Private Sub Form_Load()
Text1.Visible = False
End Sub
Public Function Average(Flag As Boolean)
Dim Count As Integer
Dim Continue As Integer
Dim X(1 To 500) As Integer
Flag = True 'initialize
Counter = 1
Total = 0
Do Until Not Flag
X(Counter) = InputBox("Enter number" & Counter, "Enter number")
Continue = MsgBox("Do you wish to enter more numbers?",vbYesNo, "Continue?")
Total = Total + X(Counter)
Counter = Counter + 1
Select Case Continue
Case vbYes
Flag = True
Case vbNo
Flag = False
End Select
Loop
Average = Total / (Counter - 1) 'subtract one due to
Text1.Visible = True 'initlizing at 1.
Text1.Text = Average 'print
End Function
Find the average of up to 500 numbers using an array Comments
No comments yet — be the first to post one!
Post a Comment