Hi, can anyone please shed me some light: I'm doing random values in arrays, but I need to get a 100 sharp as the total value:
But the problem is, sometimes this acc generates 99 or even > 100, am I missing something here? :confused:
Code:
Private Sub Command1_Click()
Dim Num(1 To 10) As Single, total As Single
Dim div As Single, acc As Single
Dim strRes As String
Dim i As Integer
For i = 1 To 5
Num(i) = Int(Rnd * 100) + 1
total = total + Num(i)
Next i
For i = 1 To 5
div = Round((Num(i) / total) * 100)
acc = acc + div
strRes = strRes & div & vbNewLine
Next i
Label1.Caption = strRes & "____ +" & vbNewLine & _
Round(acc)
End Sub