Question

Write a C++ program that simulates flipping a coin (random numbers) 1000 times and displays the...

Write a C++ program that simulates flipping a coin (random numbers) 1000 times and displays the number of heads and tails. Note that there is no input to the program and the number of heads and tails will be around 500.

Homework Answers

Answer #1

#include <iostream>
using namespace std;

int main() {
srand(time(NULL));
int heads = 0, tails = 0;
for(int i=0; i<1000; i++)
{
if(rand() % 2 == 0)
heads++;
else
tails++;
}
cout << "Heads = " << heads << endl;
cout << "Tails = " << tails << endl;
}

// Please up vote

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
java beginner level NO ARRAYS in program Flip a coin (Assignment) How many times in a...
java beginner level NO ARRAYS in program Flip a coin (Assignment) How many times in a row can you flip a coin and gets heads? Use the random number generator to simulate the flipping of the coin. 0 means heads, 1 means tails. Start a loop, flip it, if heads, count it and keep flipping. If tails, stop the loop. Display the number of times in a row that heads came up. Once this is working, wrap a while loop...
Suppose you are flipping an unfair coin 10 times. Let p be the probability of getting...
Suppose you are flipping an unfair coin 10 times. Let p be the probability of getting tails for said coin. Define X to be the number of heads obtained. (a.) Describe the sample space S. (b.) Give the values x for X. (c.) Find the likelihood of rolling exactly four heads. (d.) Find fX(x) .
Slim and Roy are flipping a unfair coin, where the coin has the chance to land...
Slim and Roy are flipping a unfair coin, where the coin has the chance to land on heads 65% of the time. Every time that the coin lands on heads, Slim gets 500 dollars from Roy, and Roy gets 500 dollars from Slim if the coin lands on tails. If the game is played 100 times (coin is flipped 100 times), what is the probability that Slim's winnings are $20,000 more than Roy's, where 'x' is strictly greater than 20,000...
Consider a simple experiment that involves flipping a coin 8 times and recording the number of...
Consider a simple experiment that involves flipping a coin 8 times and recording the number of heads. We’ll suppose that this experiment has been performed many times, and we’ll look to see whether the results are consistent with the coin being fair. Define the random variable X to be the number of heads observed in 8 flips of the coin. Q1: If the coin is fair, what is the distribution of X? Name it and give the values of the...
Write and solve an equation for the total number of possible combinations from flipping a coin...
Write and solve an equation for the total number of possible combinations from flipping a coin 10 times.​ 3. In two or more complete sentences, describe the relationship between the terms of the equation and the number of combinations when flipping a coin 10 times. 4. What is the theoretical probability of getting exactly 5 heads in a sequence of 10 flips?
A game is played by first flipping a fair coin, then rolling a die multiple times....
A game is played by first flipping a fair coin, then rolling a die multiple times. If the coin lands heads, then die A is to be used; if the coin lands tails, then die B is to be used. Die A has 4 red and 2 white faces, whereas die B has 2 red and 4 white faces. If the first two throws result in red, what is the probability that the coin landed on heads?
Use the Excel Program to generate a uniform distribution and then show that a flipping fair...
Use the Excel Program to generate a uniform distribution and then show that a flipping fair coin many times will result in having a 50% chance of landing heads up and a 50% chance of landing tails up.
Write a C++ program that asks the user to enter in three numbers and displays the...
Write a C++ program that asks the user to enter in three numbers and displays the numbers in ascending order. If the three numbers are all the same the program should tell the user that all the numbers are equal and exits the program. Be sure to think about all the possible cases of three numbers. Be sure to test all possible paths. Sample Runs: NOTE: not all possible runs are shown below. Sample Run 1 Welcome to the order...
Write 15 probability measures for flipping a coin 3 times:
Write 15 probability measures for flipping a coin 3 times:
1) An irregular coin (? (?) = ?? (?)) is thrown 3 times. ? discrete random...
1) An irregular coin (? (?) = ?? (?)) is thrown 3 times. ? discrete random variable; ? = "number of heads - number of tails" is defined. Accordingly, ? is the discrete random variable number of heads - number of posts a) Find the probability distribution table. b) Cumulative (Additive) probability distribution table; ? (?) c) Find ? (?≥1).
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT