Question

In C++ Create a program that rolls two dice. It should roll these dice multiple times...

In C++

Create a program that rolls two dice. It should roll these dice multiple times to find the probability of having the sum of the rolls add to 7. You should use a loop to roll the dice and use a counter to keep track of how many times they add to seven.

Homework Answers

Answer #1
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main() {
    srand(time(NULL));
    int count = 0, total = 100000;
    for (int i = 0; i < total; ++i) {
        if ((1 + rand()%6) + (1 + rand()%6) == 7) {
            ++count;
        }
    }
    cout << "the probability of having the sum of the rolls add to 7 is " << count/(double)total << endl;
    return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
please create a C++ program that will ask the user how many times to roll a...
please create a C++ program that will ask the user how many times to roll a pair of dice. The choices are 10, 20 & 50. Allow the user to select 1 choice and error if none of the choices are valid. The program will then the desired amount. The program will keep track of the running total of the sum of the dice (i.e. 5, 2 = 7; 3,6 =7+9 = 16). The program will then produce the total...
Dice Rolling) Write an application to simulate the rolling of two dice. The application should use...
Dice Rolling) Write an application to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the...
You roll a pair of fair dice 20 times. Each time, the sum of the two...
You roll a pair of fair dice 20 times. Each time, the sum of the two dice values is recorded. What is the probability that you will roll an 7 (the sum of the two dice values = 7) at least (5) times? Assuming that each roll of the dice is independent
Using Python : consider the following experiment: You roll a pair of fair dice and calculate...
Using Python : consider the following experiment: You roll a pair of fair dice and calculate the sum of the faces. You are interested in the number of rolls it takes until you get a sum of "7". The first time you get a "7" the experiment is considered a "success". You record the number of rolls and you stop the experiment. You repeat the experiment N=100,000 times. Each time you keep track of the number of rolls it takes...
1) Roll two dice 10 times. Record the sum of the dice for each roll. Find...
1) Roll two dice 10 times. Record the sum of the dice for each roll. Find the mean, standard deviation, and construct a histogram from the data.2) Roll two dice 50 times. Record the sum of the dice for each roll. Find the mean, standard deviation, and construct a histogram from the data.3) Roll two dice 100 times. Record the sum of the dice for each roll. Find the mean, standard deviation, and construct a histogram from the data.4) Summarize...
Simulate 1000 rolls of a pair of dice. (Hint: Sounds like a For Loop to me!)...
Simulate 1000 rolls of a pair of dice. (Hint: Sounds like a For Loop to me!) Write a program that simulates a dice roll by picking a random number from 1-6 and then picking a second random number from 1-6.    How many times do you get two 1’s. What many times do you get two 1’s if you simulate 10,000 rolls of a pair of dice? Upload your program and type the answer to the two questions. (remember, these...
If you roll two dice what’s the probability of rolling a seven the numbers on the...
If you roll two dice what’s the probability of rolling a seven the numbers on the dice add up to seven on or before the eight roll?
Answer the following two questions. 1. If you roll two dice, what is the probability of...
Answer the following two questions. 1. If you roll two dice, what is the probability of not getting a sum of 7? 2. If you roll two dice, what is the probability the sum is a 4, 7, or 10?
a. Roll a dice, X=the number obtained. Calculate E(X), Var(X). Use two expressions to calculate variance....
a. Roll a dice, X=the number obtained. Calculate E(X), Var(X). Use two expressions to calculate variance. b. Two fair dice are tossed, and the face on each die is observed. Y=sum of the numbers obtained in 2 rolls of a dice. Calculate E(Y), Var(Y). c. Roll the dice 3 times, Z=sum of the numbers obtained in 3 rolls of a dice. Calculate E(Z), Var(Z) from the result of part a and b.
We roll 2 fair dice 3 times, and each time we add up the two outcomes....
We roll 2 fair dice 3 times, and each time we add up the two outcomes. Thus we have 3 sums (each sum is between 2 and 12). What is the probability that we always have the same sum?