|
-
Apr 14th, 2005, 10:12 PM
#1
Thread Starter
New Member
VB Array Question
Learning Visual Basic .NET (7.1)
I have to design a loop that will "roll" the dice and then
drop the lowest number
then sum the other three numbers together
then store these values somewhere
keep doing this until all possible rolls are exhausted
when that happens I need to display each possible result and the dice that rolled them
ie, result sum of 10 all rolls that produced that result (1,5,2,3), (2,2,4,4), (6,1,3,1), (1,3,1,6), etc
also then ineed to display a label that shows the average result
the label is not my problem
that loop is tallied with an array and getting that working is my problem
Can anyone help??
Last edited by Scorps53; Apr 14th, 2005 at 10:57 PM.
-
Apr 14th, 2005, 11:24 PM
#2
Re: VB Array Question
Homework?
Show us exactly where you're stuck, and show the code you've got so far.
-
Apr 14th, 2005, 11:59 PM
#3
Thread Starter
New Member
Re: VB Array Question
 Originally Posted by mendhak
Homework?
Show us exactly where you're stuck, and show the code you've got so far.
as for the homework ?
Yes, I've been working on it since monday but now I'm just not getting it so I'm giving in and seeking help!
It's due 2morrow morning at 11:00 AM EXACTLY
_____________________________
Warning just in the middle of trying something different so everything is all over the place, but here it is:
Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
'Array to hold the frequency of each result
Dim sum(3) As Integer
Dim overAllSum As Integer = 168 'initialize overall sum of summed rolls
Dim rollCount As Integer = 0 'initialize count of all rolls
Dim overAllAverage As Decimal 'to hold over the all average
Dim oneRoll As Integer
Dim count As Integer
Dim dieA As Integer
Dim dieB As Integer
Dim dieC As Integer
Dim dieD As Integer
For Each rollCount In tally
oneRoll = processOneRoll()
lstFrequencyTable.Items.Add(processDisplayList())
count += 1
Next rollCount
'average the results and display in label
'overAllAverage = (overAllSum / rollCount)
lblOverAllAverage.Text = "The average result is: " & FormatNumber(overAllAverage, 2)
End Sub
Sub processDisplayList(ByVal die1 As Integer, ByVal die2 As Integer, _
ByVal die3 As Integer, ByVal die4 As Integer, _
ByVal count As Integer)
lstFrequencyTable.Items.Add((count) & " (" & die1 & ", " & _
die2 & ", " & die3 & ", " & die4 & ")")
End Sub
Function processOneRoll() As Integer
Dim dieA As Integer
Dim dieB As Integer
Dim dieC As Integer
Dim dieD As Integer
Dim sum As Integer
dieA += 1
dieB += dieA
dieC += dieA
dieD += dieA
sum = die2 + die3 + die4
Return sum
End Function
End Class
-
Apr 15th, 2005, 01:07 AM
#4
Thread Starter
New Member
Re: VB Array Question
 Originally Posted by mendhak
Homework?
Show us exactly where you're stuck, and show the code you've got so far.
Event handling specifications:
When the run button is clicked, the program will compute the result for all possible die rolls, tally the results, and display the frequency table in a list box, and the average result in a label.
Other requirements:
Must properly design your logic, using Sub procedures and functions as appropriate
Must use an array to tally the frequency of each result.
Shouldn't use any Class-level variables.
-
Apr 15th, 2005, 01:11 AM
#5
New Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|