Assistance needed with a c++ lottery program!!

I am trying to figure out how to make a program that determines what the chance is of winning a Powerball style lottery. To do this, I need to generate a "winning" ticket then see how many times it takes to draw the same ticket.
So basically, I need to write a program to generate 6 random numbers in the range of 1 to 50. Store these in an array named 'win'. In a loop, generate sets of 6 random numbers and store in another array. Compare the contents of this array against the 'win' array. Quit when they match. Count the number of times it takes to win. Repeat the whole process 10 times and average the counts.

And i'm stumped. Any help?
What do you have so far?
Or you could just calculate the possible combinations and boom, you have your answer.

The formula would be x!/y!(x-y)!
Where x = total number of balls and y = number of balls drawn.

For 5 balls drawn out of a pool of 50, the chance of winning is 1 in 2,118,760

Doing the brute force method, averaging multiple iterations won't get what you're trying to accomplish either.
I could go to a stat analyst to figure out my answer, but what i am trying to do is create a program that will simulate the lottery. So here is what I have so far. I know it isn't the best but its all I could come up with on my own as a beginner:

//Jared Rietveld

// C/C++

// 810:036:01

// Assignment 4





//function prototype to generate random ticket



void gen(int new[]){

int temp;

for (int i = 0; i < 6; i++) {

AGAIN : temp = 1 + rand() % 20;

for (int j = 0; j < i; j++){

if ( temp == t[j]) goto AGAIN;

}

new[i] = temp;

}

}





// function prototype that compares the win ticket array with our new ticket



int comp(int win[], int new[]){

int flag

for (int i = 0; i < 6; i++){

flag = 0;

for (j = 0; j < 6; j++) {

if ( win[] == new[]) {flag = 1; break;}

if (flag == 0) return 0;

}

return 1;

}

}



int main() {



int total = 0;

int avg = (total / 10);

unsigned int count = 0;



for (k = 0; k < 10; k++){



gen( win[])

while(1){

count++;

gen ( new[]);

if ( comp( win[], new[]) break;

}

}

As I said, it is not quite there and I cant even get it to compile. I would really appreciate the help. Thanks
You need to declare win[] somewhere, and find a different name for new[]. Function parameters are NOT variable declarations. They just specify the type of variable (or object) getting passed to the function.

Don't use goto. Just... don't.

Only 1 of your three for loops is properly declaring it's loop variable.

Please use code tags.
Last edited on
what are code tags? I'm sorry if I'm an idiot but I'm just trying to learn... So i fixed my for loops but don't know why new needs a different name.
Topic archived. No new replies allowed.