Hi all!
So I've come across a homework problem that's leaving me rather frustrated,
I've done the first part that entails I generate a list of 100 random numbers, then divide each number by 10 to get a single digit result, I then use this digit to find out how many lots of number groups exit, allow me to elaborate with an example.
So as you can see, this code will take our 100 random numbers and count how many fit into each number group,
that's all well and good, but now the challenge!
I essentially need to do the same thing, but instead of numbers between 0-99, I'm generating numbers between 1.0-2.75...yup decimals!
Here's my code thus far
The number groups for these numbers need to be as follows
I've tried a few methods, including converting the numbers into whole numbers and then dividing by 9, but alas nothing so far is giving me the desired results, perhaps some fresh eyes tomorrow morning will yield better results, even so, if someone could give me a shove in the right direction, I'd really appreciate it!
thanks for your time.
So I've come across a homework problem that's leaving me rather frustrated,
I've done the first part that entails I generate a list of 100 random numbers, then divide each number by 10 to get a single digit result, I then use this digit to find out how many lots of number groups exit, allow me to elaborate with an example.
VB.NET:
Dim generator As Random = New Random(DateTime.Now.Millisecond)
Dim ageCount(0 To 99) As Short
Dim ageGroupNo As Short
Dim Age As Short
lst_output.Items.Clear()
lst_output.Items.Add("Age:" + vbTab + "Count:")
For i = 0 To 99 [COLOR=#0000cd]-for 100 iterations[/COLOR]
Age = generator.Next(0, 100) [COLOR=#0000cd]-generate a random number between 0-99[/COLOR]
ageGroupNo = Age \ 10 [COLOR=#0000cd]-divide that number 10 [/COLOR]
ageCount(ageGroupNo) += 1 [COLOR=#0000cd]- increment the counter for that number group[/COLOR]
Next
Dim groups As New List(Of String)
[COLOR=#0000cd]-This simply adds the groups to a list box(0-9, 10-19,20-29..etc[/COLOR])
For i = 0 To 9
groups.Add(CStr(i * 10) + "-" + CStr((i * 10) + 9))
Next
For i = 0 To 9
lst_output.Items.Add(CStr(groups(i)) + vbTab + CStr(ageCount(i))) [COLOR=#0000cd]-Output data[/COLOR]
Next
So as you can see, this code will take our 100 random numbers and count how many fit into each number group,
that's all well and good, but now the challenge!
I essentially need to do the same thing, but instead of numbers between 0-99, I'm generating numbers between 1.0-2.75...yup decimals!
Here's my code thus far
VB.NET:
Dim generator As Random = New Random(DateTime.Now.Millisecond)
Dim heightCount(0 To 99) As Decimal
Dim heightGroupNo As Decimal
Dim Height As Decimal
lst_output.Items.Clear()
For i = 0 To 99
Generate:
Height = Math.Round(generator.NextDouble() * 2.75, 2) [COLOR=#0000cd]-Generate number no greater than 2.75[/COLOR]
If Height < 1.0 Then [COLOR=#0000cd]- Make sure number is at least 1.0[/COLOR]
GoTo Generate
End If
heightGroupNo = (Height / 9) [COLOR=#0000cd]-THIS is what I need to work out I believe[/COLOR]
heightCount(heightGroupNo) += 1 [COLOR=#0000cd]- increment the counter for that number group[/COLOR]
Next
For i = 0 To 8
lst_output.Items.Add(CStr(heightCount(i))) [COLOR=#0000cd]- Output data[/COLOR]
Next
The number groups for these numbers need to be as follows
VB.NET:
1.00 - 1.19
1.20 - 1.39
1.40 - 1.59
1.60 - 1.79
1.80 - 1.99
2.00 - 2.19
2.20 - 2.39
2.40 - 2.59
2.60 - 2.75
I've tried a few methods, including converting the numbers into whole numbers and then dividing by 9, but alas nothing so far is giving me the desired results, perhaps some fresh eyes tomorrow morning will yield better results, even so, if someone could give me a shove in the right direction, I'd really appreciate it!
thanks for your time.