Bullseye

Hello!

I'm trying to make a bulls function! On average I would like it to hit the Bull 70% of the time and the other 30% (miss) between 1 to 20. As you can see I have the basic code, but I'm just learning so don't really understand what each part does.

1
2
3
4
5
6
7
8
9
int Bull() 
{
        int percent = rand()%100; //lower percent is more throws needed
        int r = rand()%100; //lower r is less throws needed
        if(r<percent)        // hit
        return 50;
        else            // miss
        return 1 + rand()%20;
}


Thanks!
hope that helps o_O

1
2
3
4
5
6
7
8
9
int Bull() 
{
    int percent = rand()%100; // random number between 0 .. 99
    int r = rand()%100; // random number between 0 .. 99
    if(r<percent) // if r is lower…
        return 50; // function will return 50
    else // miss
        return 1 + rand()%20; // random number between 1 .. 20
}


regards
Topic archived. No new replies allowed.