Hi, I am new to C++ and I am trying to teach myself. I am currently working on the Birthday Paradox. My code is below, I think the way I am initializing the arrays correctly. If anyone can help me I would greatly appreciate it.
array index goes from 0 to size-1
in your case you may access birthdays[0] to birthdays[49] trying to use birthdays[50] is a logic error that causes undefined behaviour.
line 27 would be executed (trials+1)*49 times. So you may have a probability greater than 1.
I don't understand your logic, please write the pseudocode.
> If anyone can help me I would greatly appreciate it.
be clear about what you need help with (erroneous results, crash, compilation errors, logic)
Hi, sorry I am new to programming in c++. Specifically, the probabilities are incorrect. My logic is as follows:
1) I create a for loop to loop through each 2 through 50 people and set the number of matches to 0.
2) Then I create another for loop to iterate the process of assigning random birthdays to the i and k people.
3) Then I compare to see if there is a match between the i peoples birthdays and the k peoples birthdays
Does that logic make sense?
> I create a for loop to loop through each 2 through 50 people
iirc you want to answer the probability that in a room of say 13 people there are at least two that share a birthday.
If you group is only 13, ¿why do you go through 50 people?
> assigning random birthdays to the i and k people.
¿how many times would you give a birthday to the `i' person?
¿what happens if i==k? Notice how the check on line 27 would be always true.
This is what you are doing:
- i goes from 2 to 50. There is no special meaning attached to it.
- A lot of times do:
--- Generate two random number and see if they are the same
- Divide the number of matches by 10000
Your description is too specific, you need to abstract more. By instance
- Create a group of n people
- Assign each one of them a birthday.
- Check for duplicate