# VBA

• ### Question

• Consider a game of three players. During a game, each player will roll two dices and his total will be recorded. Then points will be awarded based on the following rules:

• The player with the highest total will earn 3 points, the player with the second highest total will earn 1 point, and the player who comes last will earn nothing.
• If it is a draw between all three players, then each player will earn 1 point.
• If it is a draw between the top two players, then each of them will earn 2 points while the last player will earn nothing.
• If it is a draw between the bottom two players, then each of them will earn nothing while the top player will earn 3 points.

Assume that the dices are regular six-sided fair dices.

Let’s call the players P1, P2, and P3, respectively. Write an Excel Sub Procedure that simulates playing the game 1000 times. The results are to be displayed in a worksheet named "Sim" in a table with the following form:

 A B C D E F G 1 Game P1 Roll P2 Roll P3 Roll P1 Points P2 Points P3 Points 2 1 (2, 6) (3, 3) (3, 4) 3 0 1 3 2 (1, 2) (2, 1) (6, 5) 0 0 3 4 3 (3, 4) (2, 5) (3, 1) 2 2 0 5 4 (1, 4) (2, 3) (3, 2) 1 1 1

Hints:

• Call the function Randomize at the beginning of your Sub to set the random number generator’s seed to the system time.
• You may use Int(1 + Rnd * 6) to generate a random integer from 1 to 6.

Attach your Sub Procedure to a button so that the table is generated and displayed when the button is pressed.

Tuesday, March 31, 2020 3:18 PM

### All replies

• You want us to do your homework?

Regards, Hans Vogelaar (http://www.eileenslounge.com)

Tuesday, March 31, 2020 6:31 PM