Calculating percent on a dice game

I have an assignment were I had to make a dice game. Well I finally go the program and now he wants percentages and more of the dice game played 20000 times. I'm not sure where to start but i know i need a for loop.

Here is what he wants:
After your program can play the game once correctly, add a loop so that it plays the game 20000 times. Add counters that count how many times the player wins (and where), and how many times the player loses. Post your answers on the Discussion board as soon as you get them.
3.1 After the 20000 games, compute the percentage of times the player will win. Output this value.
3.2 What is the percentage of times the player will win on the first roll? Output this value.
3.3 What is the percentage of times the player will win by rolling a 7 in the second part of the game? Output this value.

here is my program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  #include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()  {

	int rollADie1, rollADie2, totalDice = 0, key;
	

	srand(time(0));  // call this only once – seed the random generator

	rollADie1 = rand() % 6 + 1;  // in the range of 1 - 6
	rollADie2 = rand() % 6 + 1;  // in the range of 1 - 6

	printf("Dice #1 is %i\n", rollADie1);
	printf("Dice #2 is %i\n", rollADie2);

	totalDice = rollADie1 + rollADie2;
	printf("The total of both dice is %d\n", totalDice); 

	if (totalDice == 7 || totalDice == 11)
		printf("Win\n");
	else
	if (totalDice == 2 || totalDice == 3 || totalDice == 12)
		printf("Lose\n");
	else
	if (totalDice >= 4 && totalDice <= 6 || totalDice >= 8 && totalDice <= 10)
	{
		key = totalDice;
		printf("Setting key to %d\n\n", key);
		do
        {
			rollADie1 = rand() % 6 + 1;  // in the range of 1 - 6
			rollADie2 = rand() % 6 + 1;  // in the range of 1 - 6

			totalDice = rollADie1 + rollADie2;
			printf("The total of both dice is %d\n", totalDice);

			if (totalDice >= 4 && totalDice <= 6 || totalDice >= 8 && totalDice <= 10)   {
				printf("Lose\n");
			}
			else
			{
				if (totalDice == 7) {
					printf("Win\n");
				}
			}
		} while (totalDice == 2 || totalDice == 3 || totalDice == 11 || totalDice == 12);
	}

	system("pause");
}
Put everything between lines 9 and 50 in a for loop counting from 0 to 20000. Instead of printing out that the player won or lost, increment a counter each time (you'll need one counter for wins and one for losses).

% times player wins == win / 20000

You'll need two more counters for the other two things you need to check.

Remove all of your print functions before you test this. They can really slow down a program.
Ive replied to your private message CDavis
Topic archived. No new replies allowed.