15,742,477 members
See more:
how to make calculates the average of up to 30 numbers input by the user and stored in array . the program should use a class named statistical and have an stornumber method that stores number into an array one at a time . the class should have a count property that keeps track of the number stored and a method called average the returns the average of the number . i have 2 textbox and 2 button

textbox 1 = number

textbox2 = read only result of average

button 1 = record the number

button 2 = calculates the average

Posted
Peter Leow 4-Apr-14 6:51am
Homework? What have you tried?

## Solution 1

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

This isn't difficult: a For Each loop through the array, adding up all the values. Divide by the number of values in the array, and you have the average...

Member 10724294 4-Apr-14 8:42am
ok
thank you
i undrostod my homworl but idon't now how made form cod

i wrote the class like this can you correct it for me

Public Class Statistical
Private m_num As Double
Private nums(30) As Double
Public Sub stornumber(ByVal num As Double)
If m_num < 29 Then
nums(m_num) = num
m_num += 1
End If
End Sub

Public ReadOnly Property count() As Double
Get
Return m_num
End Get
End Property

Function average() As Double
Dim sum As Double = 0
For Each n As Double In nums
If n <> 0 Then sum += n

Next
Return sum / count
End Function
OriginalGriff 4-Apr-14 9:49am
No, I can't - that is...um...very wrong?
Think about it: you want to work out averages, so why would you set all the values the same? I think I can guess the average of any size array, if all the values are the same... :laugh:
And where do you count the numbers?

Have you met generic Lists yet?