Intro to Computer Science
Project 2: Loops (and booleans and math)

Due: At 11:59pm  Mon March 4

Summary: In this project you will use loops to help calculate how many times you should  repeat an activity before the reaching a threshold chance that an event will occur during one of the repetitions. This project will be a computer based project instead of a robot project.


You may remember from your study of probability that we often have a random event where each succeeding event is unaffected by previous events. For example, if we roll a fair die we have a 1 in 6 (16.67%) chance of rolling a 6.

What if we wanted to know how many rolls it would take to have a good chance of rolling at least one 6?

Each event has a 16.67% chance of rolling the 6. If we have rolled 10 times and gotten 1, 4, 3, 2, 4, ,3, 5, 5, 1, 1 so far, we still have only a 16.67% chance or rolling a 6 on the 11th roll. However, we can calculate how many rolls we much do before we have a 50% or better probability that at least one of the rolls will have been a 6. We do this by calculating how many rolls we need before we have a 6 and then watching for probability to go below 50%.

To caculate the probability that all of the rolls will be of a certian value range we now have an independent probability problem. When calculating probabilities which do not depend on other probabilities we multiply them together. For for the example above: we have an 83.33% chance to roll something other than a 6 when rolling a fair die.

So the chance of not rolling a six on any roll of a fair die:

Number of die rolls
Chance that none of the die rolls is a six
69.44% (.8333*.8333)
57.86% (.83333)
48.22% (.83334)
40.18% (.83335)

So from the above table we can see that we cross the 50-50 threshold for rolling a 6 at least once in all of our rolls when we have rolled the die 4 times.

The Program:

Your Job is to write a program which implements this property to calculate when a set of low probability events crosses a user designed threshold.

You must ask the use for the following data:
then you must calculate the expected number of events it will take to achieve your proscribed level of probability that at least one desired result will occur.

Additional Restrictions on your program for good programming

Sample output from my implementation. Note that what the program printed is in black text, what I (as the user) typed is in green:

Please enter your activity name:Winning the Lottery
Please enter the probability that it will occur in one event:0.0001
please enter your desired minimum probability of the activity
  occurring at least once in all of the events: 50
For your activity of Winning the Lottery
 with a probability of success of 0.0001 for each event
 you need to have 6932 events  to have a 50% chance of doing so in one of those 6932 events


again zip up your project folder and submit it to me by email. Make sure that your submitted zip file contains your first initial and last name as part of the zip file name.