Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Visual Basic Dice Roll Simulator Create an application that simulates rolling a

ID: 644762 • Letter: V

Question

Visual Basic Dice Roll Simulator

Create an application that simulates rolling a pair of dice. When the user clicks a
button, the application should generate two random numbers, each in the range of
1 through 6, to represent the value of the dice.

Display in a listbox your 100 rolls of two random dice. Display the sum of the two dice.

EX: Roll 1: 2 + 4 = 6, which displays the roll number, the two die, and the sum!

Keep track how many times one of the 11 possible sums are rolled when rolls are complete, display the grand total for each different roll in 11 labels

IT CAN NOT USE ARRAYS. I am not on Arrays in class yet, otherwise I have the program done for most part. Below is what I have with Arrays, so I really only need help on removing them, but to do the same thing. I'm guessing with some sort of counting loop?

-----------------------------------------------------------------------------------------------------------

Dim shooter As New Random()

Dim die1 As Integer

Dim die2 As Integer

Dim die1Value As Integer

Dim die2Value As Integer

Dim total As Integer

Dim icount As Integer = 0

Dim iArray(11, 1) As Integer

Dim iIndex As Integer = 0

Dim iCnt As Integer = 1

Dim iCount1 As Integer

Dim blnExists As Boolean = False

Do Until lstRolls.Items.Count = 100 ' Run Loop until 100 rolls show

die1 = shooter.Next(6)

die2 = shooter.Next(6)

die1Value = die1 + 1

die2Value = die2 + 1

total = die1Value + die2Value

' add the total to a two dimensional array along with the number of times it appears

' if already added increase the count

For iCount1 = 0 To 10

If (iArray(iCount1, 0) = total) Then

iArray(iCount1, 1) = iArray(iCount1, 1) + 1

blnExists = True

Exit For

End If

Next

' if not added add to the array

If (blnExists = False) Then

iArray(iIndex, 0) = total

iArray(iIndex, 1) = iCnt

iIndex = iIndex + 1

End If

blnExists = False

lblDie1.ImageIndex = die1

lblDie2.ImageIndex = die2

lstRolls.Items.Add(die1Value.ToString() & " + " & die2Value.ToString() & " = " & total.ToString())

lstRolls.SelectedIndex = lstRolls.Items.Count - 1

Explanation / Answer

public static int rollDice() {
   int Min = 1;
   int Max = 6;
   int result = Min + (int)(Math.random() * Max);
   return result;
   }

   public static void main (String[] args) {
   int dice1;
   int dice2;
   int total = 0;

   do {
   dice1 = rollDice();
   total += dice1;
   dice2 = rollDice();
   total += dice2;
   System.out.println( "Dice, Dice Two = "+dice2);
   if (dice1 == dice2) {
   System.out.println( "Dice are equal: have another throw");
   }
   } while (dice1 == dice2);

   System.out.println( "Total = " + total);
   }
}