S
Sandra
I was given this problem for extra credit and I am just stuck !
BTW - I am not asking for source code and I am not asking anyone to do
my homework as I do want to learn .. I just need a hint or two to get
moving and I need to know if what I have written so far is leading me
in the right direction ~
Ok - The problem is to find out how many people need to be in a room
for a 95% chance that someone in that room will match my birthday
I wrote a program that will calculate that percentage for any 2
bithdays to match, but that is not the same thing
Here is what I have so far:
#include "stdafx.h"
#include <time.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int sample[1000];
int i=1,j=1;
int a =0;
srand( (unsigned)time( NULL ) );
while (a != 325)
{ sample=rand()%365+1;
//cout<<" "<<sample;
a = sample;
i++;
if (a==325) cout<<"\n\n\n Match "<<a<<" at "<<i<<"\n";
}
return 0;
This puts random numbers from 1-365 in an array - reads the array and
tries to detect an exact match
The problem is that the match is so random - how do I come up with a
95% chance? Is there any exact answer ?
As I said - just need some hints to move along..
Any replies will be appreciated,
Thanks,
Sandra
BTW - I am not asking for source code and I am not asking anyone to do
my homework as I do want to learn .. I just need a hint or two to get
moving and I need to know if what I have written so far is leading me
in the right direction ~
Ok - The problem is to find out how many people need to be in a room
for a 95% chance that someone in that room will match my birthday
I wrote a program that will calculate that percentage for any 2
bithdays to match, but that is not the same thing
Here is what I have so far:
#include "stdafx.h"
#include <time.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int sample[1000];
int i=1,j=1;
int a =0;
srand( (unsigned)time( NULL ) );
while (a != 325)
{ sample=rand()%365+1;
//cout<<" "<<sample;
a = sample;
i++;
if (a==325) cout<<"\n\n\n Match "<<a<<" at "<<i<<"\n";
}
return 0;
This puts random numbers from 1-365 in an array - reads the array and
tries to detect an exact match
The problem is that the match is so random - how do I come up with a
95% chance? Is there any exact answer ?
As I said - just need some hints to move along..
Any replies will be appreciated,
Thanks,
Sandra