Question

In: Computer Science

Write a complete C++ program to display the results of rolling an 8-sided die 5 times.

Write a complete C++ program to display the results of rolling an 8-sided die 5 times.

Solutions

Expert Solution

The code:

#include<iostream>
#include<time.h>
using namespace std;
int main()                        // main function
{ 
    int r;
    srand(time(0));              // initializing random number generator

    cout << "The result of rolling an 8 sided die 5 times:" << endl;
    for (int i=0; i<5; i++)             // loop is executing 5 times
    {    
        r = rand() % 8 + 1;             // generate a random number
        cout << r << "  ";              // showing the result
    }
}

The code with output:


Related Solutions

Rolling a fair six-sided die five times could result in the following sample of n =...
Rolling a fair six-sided die five times could result in the following sample of n = 5 observations: What are the mean, variance, and standard deviation?
Suppose you are rolling a fair four-sided die and a fair six-sided die and you are...
Suppose you are rolling a fair four-sided die and a fair six-sided die and you are counting the number of ones that come up. a) Distinguish between the outcomes and events. b) What is the probability that both die roll ones? c) What is the probability that exactly one die rolls a one? d) What is the probability that neither die rolls a one? e) What is the expected number of ones? f) If you did this 1000 times, approximately...
Let X be the result of rolling a fair ten-sided die a) Write down the distribution...
Let X be the result of rolling a fair ten-sided die a) Write down the distribution of X, and compute its expected value. You must show all your work. b) How would you use R to simulate 4 rolls of ten-sided die and sum the result, then repeat this action 10,000 times, and store it in a variable called toss4. Please type the code in the space below.
A die is weighted so that rolling a 1 is two times as likely as rolling...
A die is weighted so that rolling a 1 is two times as likely as rolling a 2, a 2 is two times likely as rolling a 3, a 3 is two times as likely as rolling a 4, a 4 is two times a likely as rolling a 5, and a 5 is two times as likely as rolling a 6. What is the probability of rolling an even number?
The experiment of rolling a fair six-sided die twice and looking at the values of the...
The experiment of rolling a fair six-sided die twice and looking at the values of the faces that are facing up, has the following sample space. For example, the result (1,2) implies that the face that is up from the first die shows the value 1 and the value of the face that is up from the second die is 2. sample space of tossing 2 die A pair of dice is thrown. Let X = the number of multiples...
Write a C++ program to display toy name
Write a C++ program to display toy name
Consider rolling both a fair four-sided die numbered 1-4 and a fair six-sided die numbered 1-6...
Consider rolling both a fair four-sided die numbered 1-4 and a fair six-sided die numbered 1-6 together. After rolling both dice, let X denote the number appearing on the foursided die and Y the number appearing on the six-sided die. Define W = X +Y . Assume X and Y are independent. (a) Find the moment generating function for W. (b) Use the moment generating function technique to find the expectation. (c) Use the moment generating function technique to find...
PROJECT C Roll a 6-sided die 800 times. If you do not desire to roll a...
PROJECT C Roll a 6-sided die 800 times. If you do not desire to roll a die manually, STATDISK can be used to simulate the process. To use STATDISK, go to “Data” at the top of the STATDISK window, and then choose “Dice Generator”. The “Dice Roll Random Sample Generator” window will appear. Then in that window, put 800 in for “Sample Size”, put 1 in for “Num Dice”, and put 6 in for “Num Sides”. Please disregard the “Random...
1. The experiment of rolling a fair six-sided die twice and looking at the values of...
1. The experiment of rolling a fair six-sided die twice and looking at the values of the faces that are facing up, has the following sample space. For example, the result (1,2) implies that the face that is up from the first die shows the value 1 and the value of the face that is up from the second die is 2. (1,1)       (1,2)       (1,3)       (1,4)       (1,5)       (1,6) (2,1)       (2,2)       (2,3)       (2,4)       (2,5)       (2,6) (3,1)       (3,2)       (3,3)       (3,4)       (3,5)       (3,6)...
What is the probability of rolling 6, 6 sided die and achieving a score of 18?...
What is the probability of rolling 6, 6 sided die and achieving a score of 18? (6 die, each one is 6 sided)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT