I need to create a program that calculates out what percentage chance any of 3 randomly generated numbers (1-100) is higher than 99.
Can you help me break this down into smaller parts so it's easier to accomplish?
I need to create a program that calculates out what percentage chance any of 3 randomly generated numbers (1-100) is higher than 99.
Can you help me break this down into smaller parts so it's easier to accomplish?
Sounds like you need to know the probability of one of three events occurring, with each event having a 1/100 chance.
After you have figured out the formula it should be relatively simple to implement.
I am sorry, but if you don't rephrase your question, the majority of the stackoverflow users will have no idea how to solve your puzzle.
I took a stab at making your question a little more clear. Go ahead and revert me if I mis-construed the meaning of the assignment.
From what I can tell you've got two basic approaches, and which to take will probably depend on what kind of class you are in:
You could determine the probability Anaylytically using a formula. Some basic probability rules might help you out.
You could also test out the problem Empirically by generating many (say, tens of thousands) of random numbers (1-100) and count how many times you succeeded/failed.
Sounds like they want you to do a simulation: actually pick three number randomly, check the results for that instance, and store them somewhere so you can aggregate them when you're done.
But we need to see more of your own work first before I give you more than that.
This is simple probality mathematics i.e. each random number has a prob of 1/100 of being greater than 99
Well this is a fairly simple math/ probability problem but I assume the exercise is to show it with code.
Make a loop of code that generates the 3 numbers, and indicates if any of them were above 99.
Add to a counter if one was over 99.
Run the loop 10,000,000 times and then display your counter over 10,000,000 to get the percentage that passed.
Did you perhaps mean: "The probability that the sum of any three numbers from 1-100 would be greater than 99"?
You don't need a program to give an answer when there is exact answer already.
Because these three events are indepedentent of each other and the chance of the
The chance of of a number to be higher than 99 is 1/100.
The chance of such event not happening is 99/100.
The chance of no number being higher than 99 is (99/100)^3, because the events are independent of each other. The change of opposite to be true is 1 - (99/100)^3.
I am sure you can code such a formula in C#.
double eventProb = (100-99)/(double)100*(99/(double)100)*(99/(double)100);
int eventCount = 3;
double percent = eventProb * eventCount * 100;
Console.Write("{0} %", percent);
Console.OpenStandardInput();