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!

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education