Assignment4C Heads or Tails? It is said that a perfectly fair coin will return heads 50% of the time, and tails 50% of the time. Rather than have you test this theory by flipping a coin yourself, let's use a random number generator and loops to determine the truth. Create a program that prompts the user for a number of coin flips. Then, “flip a coin" that many times by using a random number generator that produces either a 0 or 1. Afterwards, show the user how many times it landed on heads (0) and tails (1) and calculate the frequency for each. Inform the user if heads or tails was the more frequency result, or if they were equal. Call the file name Assignment4C (.java, .cs, .cpp) and the class name Assignment4C. Example outputs are shown below. Note that due to using a random number generator, you may not get the same numerical results – but the formatting and wording should be the same. User input is indicated in bold. Sample Output #1: How many times do you want to flip the coin?: 100 After flipping the coin 100 time(s), we found that it lands on: Heads - 51 times (0.51%) Tails 49 times (0.49%) The coin lands on heads more often than tails! Sample Output #2: How many times do you want to flip the coin?: 1000 After flipping the coin 1000 time(s), we found that it lands on: Heads - 498 times (0.498%) Tails - 502 times (0.502%) The coin lands on tails more often than heads! Sample Output #3: How many times do you want to flip the coin?: 50 After flipping the coin 50 time(s), we found that it lands on: Heads - 25 times (0.5%) Tails - 25 times (0.5%) The coin is perfectly fair!
Assignment4C Heads or Tails? It is said that a perfectly fair coin will return heads 50% of the time, and tails 50% of the time. Rather than have you test this theory by flipping a coin yourself, let's use a random number generator and loops to determine the truth. Create a program that prompts the user for a number of coin flips. Then, “flip a coin" that many times by using a random number generator that produces either a 0 or 1. Afterwards, show the user how many times it landed on heads (0) and tails (1) and calculate the frequency for each. Inform the user if heads or tails was the more frequency result, or if they were equal. Call the file name Assignment4C (.java, .cs, .cpp) and the class name Assignment4C. Example outputs are shown below. Note that due to using a random number generator, you may not get the same numerical results – but the formatting and wording should be the same. User input is indicated in bold. Sample Output #1: How many times do you want to flip the coin?: 100 After flipping the coin 100 time(s), we found that it lands on: Heads - 51 times (0.51%) Tails 49 times (0.49%) The coin lands on heads more often than tails! Sample Output #2: How many times do you want to flip the coin?: 1000 After flipping the coin 1000 time(s), we found that it lands on: Heads - 498 times (0.498%) Tails - 502 times (0.502%) The coin lands on tails more often than heads! Sample Output #3: How many times do you want to flip the coin?: 50 After flipping the coin 50 time(s), we found that it lands on: Heads - 25 times (0.5%) Tails - 25 times (0.5%) The coin is perfectly fair!
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 19PE
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning