(1 point) Using an if Statement In a Loop
A common thing to do is to use variables to keep track of some sort of count. When used in a loop we count things very quickly.
Scenario: If you roll a pair of dice, rolling a 12 (two sixes) is rare. How rare? If you were to roll a pair of dice 1,000 times, on average, how many times would it come up as 12?
To figure this out, we could write code to run an experiment. It would go something like this:
var die1 = -1;
var die2 = -1;
var loopNum = 0; //use to count number of loops
var twelveCount = 0; //use to count 12's
while(loopNum < 1000){
loopNum++;
die1 = randomNumber(1, 6);
die2 = randomNumber(1, 6);
console.log("Rolled a " + die1 + " and a " + die2 + " for a total of " + (die1 + die2));
}
console.log("The number of times 12 was rolled was: " + twelveCount);
console.log("Done.");
The starter code sets up the whole experiment for you, except it doesn't count the number of 12's rolled - that's your job. Note: If you remove (or comment out) the console.log statement that displays every roll of the dice, the experiment will speed up A LOT! You could do tens of thousands of dice rolls in a matter of seconds.
var die1 = -1;
var die2 = -1;
var loopNum = 0; //use to count number of loops
var twelveCount = 0; //use to count 12's
while(loopNum < 1000){
loopNum++;
die1 = randomNumber(1, 6);
die2 = randomNumber(1, 6);
if ((die1 + die2)==12) {
++twelveCount;
}
}
console.log("The number of times 12 was rolled was: " +
twelveCount);
console.log("Done.");
=========================
SEE OUTPUT

Thanks, PLEASE COMMENT if there is any concern.
(1 point) Using an if Statement In a Loop A common thing to do is to...
Using the PairOfDice class from PP 4.7, design and implement an application that rolls a pair of dice 1000 times, counting the number of box cars (two sixes) that occur. You're given - //******************************************************************** // PairOfDice.java Author: Lewis/Loftus // // Solution to Programming Project 4.8 //******************************************************************** public class PairOfDice { private Die die1, die2; //----------------------------------------------------------------- // Creates two six-sided Die objects, both with an initial // face value of one. //----------------------------------------------------------------- public PairOfDice() { die1 = new Die(); die2 =...
hey, struggling with this assignment, wondering if if I could get some help. Here is the project details The following lists a Dice class that simulates rolling a die with a different number of sides. The default is a standard die with six sides. The rollTwoDice function simulates rolling two dice objects and returns the sum of their values. The srand function requires including cstdlib. my class ------------------------------------ class Dice { public: Dice(); DIce(int numSides); virtual int rollDice()const; protected: int...
This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the game of craps, a shooter rolls 2 dice and adds the dots on the upper most faces of the dice. 7 or 11 on the first roll wins, 2, 3, or 12 on the first roll loses, andthing else is call the point and the player rolls again The following program fragment uses 1-way if statements simulate the 1st roll of the dice. Replace...
With the use of python IDLE version 3.7.2, use the while loop that iterates 100,000 times. In the loop code, roll a pair of dice by generating(and summing) two random numbers in the range 1 through 6. Report to the user how many data points have been generated (i.e how many times the dice have been rolled), as in: successfully simulated 100,000 dice rolls. Create a histogram of the dice rolls showing how many times a 2 was rolled, how...
Using the previous tutorial, address the following: Imagine an experiment where three dice are tossed and the number on each die is recorded under Die1, Die2, and Die3. Answer the following questions about the sum of the three numbers recorded from: Die1+Die2+Die3. (Discussions allowed) Hint: Simulate this experiment 1000 times. (Use the same procedure as in the above tutorial, but for the Number of Variables, instead of 1 put 3, since we are rolling 3 dice not one). Next, create...
Required in C++ I'm asked to: Print a histogram in which the
total number of times the dice rolls equals each possible value is
displayed by printing a character like * that number of times.
Below is my current code. I am not allowed to use arrays or
anything too advanced as I just started the class. I would really
appreciate the help as I've been stuck on it for a while now. I can
only get it to print...
Using the previous tutorial, address the following: Imagine an experiment where three dice are tossed and the numbers on each die is recorded under Die1, Die2 and Die3. Answer the following questions about the sum of the three numbers recorded from: Die1+Die2+Die3. (Discussions allowed) Hint: Simulate this experiment 1000 times. (use the same procedure as in the above tutorial, but for the Number of Variables, instead of 1 put 3; since we are rolling 3 dice not one). Next, create...
In Python, design a program that simulates the roll of a pair of dice (two dice) and calculates the probability that various number combinations will be rolled. Let the user enter a number. This is the number of times they will roll the dice. You will roll the dice in a loop and keep track of the number of times that various rolls occur. When the loop has completed, your program should produce a table that shows the value of...
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...
need help with dice excercise
For example, if we were writing a calendar program of some sort, we might very well use an array with 366 spots to hold the days, not worrying about adding more days to the year. Exercise 23 (C level] For another example, suppose we want to simulate rolling two six-sided dice repeatedly, tallying how many times each total is rolled. We need a memory cell to count the number of times each of the possible...