I want to make a modal value calculator, So it calculates the Modal value and its repetition
The idea is to make a list of data and its repetition like shown in any Graph.
This is code you I start with:
Public Class
Dim a1(100), a2(100), Rep(100), RepMer(100), AMer(100) As Single, n, count, m As Single, z, k, c, mars As Integer
n = InputBox("How many data?", "RepTest")
count = 0
For count = 0 To n - 1
a1(count) = InputBox("Add Value", "RepTest")
Next
z = n
For run = 0 To n - 1
mars = c
z = z - 1
k = 0
For moon = 0 To (n - 1)
If a1(z) = a1(moon) Then
k = k + 1
a2(run) = a1(z)
Rep(run) = Rep(run) + k
If Rep(run) > 2 Then
Rep(run) = Rep(run) - 1
End If
End If
Next
MsgBox(a2(run)), , "Modal Value")
MsgBox(Rep(run)),, "Repetition")
Next
End Class
However, If you make the massage box outside the main 2nd loop, you have to make another loop with the same value 0 To (n-1), to match data position in an Array.
what I want you to help me please is:
I have to save the modal value and the repetition of one value in same position in the array, because if you use this code the output of n = 5 and enter value 2 ,2 ,2 ,1,1. the output will be 5 massage box with 3 equal for value 2, and 2 equal for value 1.
you can test by yourself copy the code and insert it to a form in VB.net.
With pictures:
see this link: Picture that describe the result
You can see that the output is more than one for each value, so How can I store the value and its repetition in one position in an array?
Thank you for reading, please I want a code answer. :)
Aucun commentaire:
Enregistrer un commentaire