Problem:  How many times must I will I need to throw two dice to get three 2’s, three 3’s, three 4’s, three 5’s, three 6’s, three 7’s, three 8’s, three 9’s, three 10’s, three 11’s and three 12’s.

Write a program that will roll two dice over and over until it has rolled three of each numbers.
a.  Create instance variables for the counts for each possible value.
b.  Create a function that will roll the two dice and return the sum of the two dice.
c.  Create a procedure that will display the two dice 
d.  Create a function called Triples that will check the number of times each number has been rolled and return true if each one is greater than 3, otherwise return false.
e.  The play event handler should contain a while loop that will continue to roll dice until Triples returns true and then print how many times the loop had to be executed to achieve the goal.

Can someone help me code this point me in the right direction i beleive i have most of it done just having problems with the Triples function*

Public Class diceForm
    'Enumerator for dice faces
    Enum FaceNames
        TWO = 2
        THREE = 3
        FOUR = 4
        FIVE = 5
        SIX = 6
        SEVEN = 7
        EIGHT = 8
        NINE = 9
        TEN = 10
        ELEVEN = 11
        TWELVE = 12
    End Enum 'FaceNames
    'create a random number
    Dim randomNum As Random = New Random

    'generate randomdie rolls
    Function RollDice() As Integer
        'roll the dice
        Dim die1 As Integer = randomNum.Next(1, 7)
        Dim die2 As Integer = randomNum.Next(1, 7)

        'display Image corresponding to each die
        DisplayDie(die1PictureBox, die1)
        DisplayDie(die2PictureBox, die2)

        Return (die1 + die2) 'return the sum of the dice

    End Function

    Sub DisplayDie(die As PictureBox, face As Integer)
        'File name and directory constants
        Const FILE_SUFFIX As String = ".png"
        Const File_PREFIX As String = "Images\die"

        'load corresponding image
        die.Image = Image.FromFile(File_PREFIX & face & FILE_SUFFIX)

    End Sub 'DisplayDie

    Private Sub rollButton_Click(sender As Object, e As EventArgs) Handles rollButton.Click
        'Declare Variables
        Dim count As Integer = 0

    End Sub 'rollButton

    ' display the rolls frequency
    Function Triples() As Integer
        Dim sum As Integer = RollDice()
        Dim count As Integer = 0

        ' increment and display frequency values
        Select Case sum
            Case FaceNames.TWO
                output2Label.Text = _
              Convert.ToString(Convert.ToInt32(output2Label.Text) + 1)

            Case FaceNames.THREE
                output3Label.Text = _
              Convert.ToString(Convert.ToInt32(output3Label.Text) + 1)

            Case FaceNames.FOUR
                output4Label.Text = _
              Convert.ToString(Convert.ToInt32(output4Label.Text) + 1)

            Case FaceNames.FIVE
                output5Label.Text = _
              Convert.ToString(Convert.ToInt32(output5Label.Text) + 1)

            Case FaceNames.SIX
                output6Label.Text = _
              Convert.ToString(Convert.ToInt32(output6Label.Text) + 1)

            Case FaceNames.SEVEN
                output7Label.Text = _
              Convert.ToString(Convert.ToInt32(output7Label.Text) + 1)

            Case FaceNames.EIGHT
                output8Label.Text = _
              Convert.ToString(Convert.ToInt32(output8Label.Text) + 1)

            Case FaceNames.NINE
                output9Label.Text = _
              Convert.ToString(Convert.ToInt32(output9Label.Text) + 1)

            Case FaceNames.TEN
                output10Label.Text = _
              Convert.ToString(Convert.ToInt32(output10Label.Text) + 1)

            Case FaceNames.ELEVEN
                output11Label.Text = _
              Convert.ToString(Convert.ToInt32(output11Label.Text) + 1)

            Case FaceNames.TWELVE
                output12Label.Text = _
              Convert.ToString(Convert.ToInt32(output12Label.Text) + 1)

        End Select

    End Function

    Private Sub resetButton_Click(sender As Object, e As EventArgs) Handles resetButton.Click
        ' reset the form
        Me.output2Label.Text = "0"
        Me.output3Label.Text = "0"
        Me.output4Label.Text = "0"
        Me.output5Label.Text = "0"
        Me.output6Label.Text = "0"
        Me.output7Label.Text = "0"
        Me.output8Label.Text = "0"
        Me.output9Label.Text = "0"
        Me.output10Label.Text = "0"
        Me.output11Label.Text = "0"
        Me.output12Label.Text = "0"
        Me.totalOutputLabel.Text = "0"
        Me.die1PictureBox.Image = Nothing
        Me.die2PictureBox.Image = Nothing
    End Sub 'resetButton

    Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
        'verify user wishes to quit
        Dim response As Integer
        response = MessageBox.Show("Are you sure you want to quit?", _
                                   "Exit Application", MessageBoxButtons.YesNo, _
        If response = vbYes Then
            'Exit the application 
        End If
    End Sub ' exitButton
End Class ' DiceSimulatorForm

Edited by brandon66

4 Years
Discussion Span
Last Post by Reverend Jim

I would skip the enumeration. I would also declare an array to hold the various counts such as

Private Counts() As Integer = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

Then when you generate the next rollsum you just have to do

Counts(rollsum) += 1

Checking to see if you have at least three of each is a matter of looping over the indexes from 2 to 12 and checking the value of each.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.