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
icon
Related questions
Question
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%)
49 times (0.49%)
Tails
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!
Transcribed Image Text: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%) 49 times (0.49%) Tails 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!
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning