Results 1 to 5 of 5

Thread: VB Array Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Location
    Wisconsin
    Posts
    3

    Question 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.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: VB Array Question

    Homework?

    Show us exactly where you're stuck, and show the code you've got so far.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Location
    Wisconsin
    Posts
    3

    Re: VB Array Question

    Quote 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

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Location
    Wisconsin
    Posts
    3

    Re: VB Array Question

    Quote 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.

  5. #5
    New Member
    Join Date
    Apr 2005
    Posts
    3

    Unhappy Re: VB Array Question

    hints please on at least where to start on this from what you can see I'm lost as where to start

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width