Click here to Skip to main content
15,742,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

pleas answer my q today
Posted
Comments
Peter Leow 4-Apr-14 6:51am    
Homework? What have you tried?

1 solution

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...
 
Share this answer
 
Comments
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?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900