ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   programme error (https://www.excelbanter.com/excel-programming/394192-programme-error.html)

paul[_17_]

programme error
 
the programme i wrote is to return the maximum, minimum and average of
100 numbers. But it keeps returning an error. Does anyone no whats
wrong with it? what its missing
cheers

Sub testing()
Dim a(10) As Single, max As Single
Dim min As Single, sum As Single
Dim Average As Integer, i As Integer
n = 100
max = a(1)
min = a(1)
sum = a(1)
For i = 1 To 100
If max a(i) Then max = a(i)
If min < a(i) Then
min = a(i)
End If
sum = sum + a(i)
Next i
Average = sum / n
End Sub


joel

programme error
 
a is only dimension to 10 and you are going up to 100

change dim to Dim a(100)

"paul" wrote:

the programme i wrote is to return the maximum, minimum and average of
100 numbers. But it keeps returning an error. Does anyone no whats
wrong with it? what its missing
cheers

Sub testing()
Dim a(10) As Single, max As Single
Dim min As Single, sum As Single
Dim Average As Integer, i As Integer
n = 100
max = a(1)
min = a(1)
sum = a(1)
For i = 1 To 100
If max a(i) Then max = a(i)
If min < a(i) Then
min = a(i)
End If
sum = sum + a(i)
Next i
Average = sum / n
End Sub




All times are GMT +1. The time now is 01:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com