C/C++ 编程代写
当前位置:以往案例 > >Dice game
2021-09-16

Dice Game:  A player rolls two dice, each having six sides. Each side has a number from 1 to 6.  The sum of the 2 dice is the roll total.  If a player rolls the dice and gets a roll total of 7, the player wins. However, if the roll total is not a 7, the player continues to roll until:

1) The player rolls and get the same roll total as the very first roll. The means the player wins.

2) Player rolls a 7, then the player loses

Here are some example, the number represents the roll total:

1) 4,9,12, 4   - player wins by matching initial roll

2) 4,9,12,7   - player loses by rolling a 7 before matching the initial roll

3) 7  - player wins by rolling 7 on first roll.

 

Write a C application that simulates playing the game 1000 times and count the number of wins and losses. Here are some requirements of your solution

 

1. You must have a function “rolldice” that returns the sum of two random numbers from 1-6. This function must be included as a header in your main c program.

2. The output of your program should be the number of wins, and the number of losses, based on the first number. That is , when the first number is 5, how many wins and losses are there? If the first number was 7, then there would be no losses, since the game is over with a win immediately. Print out the number of wins and losses for each first number.

3. The program should set the seed of the random number in a general way , such as using the time.

4. Submit your C files.



在线提交订单