Question

Write a program using C++ to simulate a pair of dice. Run your simulation 1000 times...

Write a program using C++ to simulate a pair of dice. Run your simulation 1000 times and record the data for the following events:

A: Sum of the outcome is even

B: Sum of the two dice is at least 10

C: The first die comes up 5

ii. Compute the probability of each event using your program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<cstdlib>

using namespace std;

int main()

{

    // Sum of the outcome is even

    int even_sum = 0;

   

    // Sum of the two dice is at least 10

    int sum_atleast_10 = 0;

   

    // The first die comes up 5

    int first_die_5 = 0;

   

    int i;

   

    for( i = 1 ; i <= 1000 ; i++ )

    {

        // generate random number in range

        int x = rand() %6 + 1;

       

        // generate random number in range

        int y = rand() %6 + 1;

       

        // Sum of the outcome is even

        if( ( x + y ) % 2 == 0 )

            even_sum++;

           

        // Sum of the two dice is at least 10

        if( ( x + y ) >= 10 )

            sum_atleast_10++;

           

        // The first die comes up 5

        if( x == 5 )

            first_die_5++;

    }

   

    cout<<"Sum of outcome is even : "<<even_sum<<endl;

    cout<<"Sum of outcome is atleast 10 : "<<sum_atleast_10<<endl;

    cout<<"First outcome is 5 : "<<first_die_5<<endl;

   

    cout<<endl;

   

    cout<<"Probability( Sum of outcome is even ) : "<<(double)even_sum / 1000.0<<endl;

    cout<<"Probability( Sum of outcome is atleast 10 ) : "<<(double)sum_atleast_10 / 1000.0<<endl;

    cout<<"Probability( First outcome is 5 ) : "<<(double)first_die_5 / 1000.0<<endl;

   

    return 0;

}


Sample Output

Add a comment
Know the answer?
Add Answer to:
Write a program using C++ to simulate a pair of dice. Run your simulation 1000 times...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This question is due my 11:50pm EST One die is rolled 2 times in a row.  ...

    This question is due my 11:50pm EST One die is rolled 2 times in a row.          The observation is the number that comes up on each roll (rolling 2 and 5 is not the same as rolling 5 and 2). Describe one outcome and find a number of outcomes. Write all outcomes of the sample space S   (you can use … notation to indicate many numbers of cases).      : “pairs are rolled” (both dice come up the same number)     Write...

  • ( Java Programming ) Write an application to simulate the rolling of two dice. The application...

    ( Java Programming ) 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...

  • 1. Roll a pair of dice, one red and one green. Now, define the following events:...

    1. Roll a pair of dice, one red and one green. Now, define the following events: A is the event that at least one of the dice will be an even number B is the event that the sum of the die will be equal to 7; C is the event that at least one of the dice is equal to 1 (a) Draw a picture of the sample space. (b) List all the outcomes for each of the events...

  • Please answer the questions clearly 1. Roll a pair of dice, one red and one green....

    Please answer the questions clearly 1. Roll a pair of dice, one red and one green. Now, define the following events: A is the event that at least one of the dice will be an even number B is the event that the sum of the die will be equal to 7; C is the event that at least one of the dice is equal to 1 (a) Draw a picture of the sample space. (b) List all the outcomes...

  • please do it in C++ Write a program that simulates the rolling of two dice. The...

    please do it in C++ Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated. [Note: Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2and 12...

  • Write a program that calls the random number generator two times to simulate rolling a pair...

    Write a program that calls the random number generator two times to simulate rolling a pair of dice. It should store the two numbers into variables. It will then determine if the dice roll is a winner (doubles OR add up to 7). Remember to add two includes and also to seed the random number generator to the clock. This will roll two dice and add them together. Doubles, or a total of 7 - YOU ARE A WINNER!!! First...

  • 1. Consider the experiment of rolling a pair of dice values showing on the dice. experiment...

    1. Consider the experiment of rolling a pair of dice values showing on the dice. experiment of rolling a pair of dice. Suppose we are interested in the sum of face a. How many simple events are possible? b. List the sample space. c. What is the probability of obtaining a 7? d. What is the probability of obtaining a value of 9 or more? Because each roll has six possible even values (2.4,6,8,10,12) and five possible odd values (3,5,7,9,11),...

  • C++ programming language, starting out with C++. Looping Constructs Write a program to simulate the casino...

    C++ programming language, starting out with C++. Looping Constructs Write a program to simulate the casino game "craps". It should execute N number of games so that you can compute the probability(%) of the "player" winning and the "house" winning. Probability(%) of the "player" winning = PlayerWins / N * 100. Probability(%) of the "house" winning = HouseWins / N * 100. The rules are: Player rolls two dice. When the sum is 7 or 11 on first throw, player...

  • PART A AND B PLEASE A pair of dice are rolled 1,000 times with the following...

    PART A AND B PLEASE A pair of dice are rolled 1,000 times with the following frequencies of outcomes Sum 2 3 4 5 6 7 8 9 10 11 12 Frequency 10 30 50 70 110 150 170 140 120 80 70 Use these frequencies to calculate the approximate empirical probabilities and odds for the events a. The sum is less than 5 or greater than 9. b. The sum is even or exactly divisible by 5. a. Probability...

  • Write a java program that simulates the rolling of four dice. The program should use random...

    Write a java program that simulates the rolling of four dice. The program should use random number generator to roll dice. The sum of the four values should then be calculated. Note that each die can show an integer value from 1 to 6, so the sum of the four values will vary from 4 to 24, with 14 being the most frequent sum and 4 and 24 being the least frequent sums. Your program should roll the dice 12,960...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT