Ok, I want to just say that this dice rolling program has been a pain in the .......... from the beginning, ok -- moving on.
I want to know if anyone at all could give me a hint as to how to find the average of multiple simulated rolls in a dice program. I know that a single roll has a 3.5 average and for two dice you multiply that times two... but what if I wanted to find the average of the sum for each of my 100000 random rolls?
Disclaimer: I know this is wrong, but....
This is what I thought of: 3.5 x 2 = 7 x 100000 = 700000 / 100000 = 7 ? ok, bare with me.
I also know that there is a 1/36 probability of rolling any number on the die. Maybe I should use this probability in the equation?
Ok guys, so you see the code. Can anyone clue me in?Code:printf("\n\nPlease input a number for the seed value: "); //User needs to input a seed value scanf("%f", &seed); srand( seed ); //implementation of the random # generator function for ( count = 0; count < 11; count++ ) // An array that makes sure the proper syncing of elements // takes place. rolls[ count ] = 0; for ( count = 1; count <= 100000; count++ ) { //A counter that calls the 'roleDie' funtion twoDice = roleDie() + roleDie(); ++ rolls[ twoDice - 2 ]; } //printf("\nthis is twodice %d\n",twoDice); //average = ( twoDice / 100000.0); printf("\n\nThe number of times the simulated roll of dice was 2: %d\n\n", rolls[0]); printf("The number of times the simulated roll of dice was 7: %d\n\n", rolls[5]); printf("The nuber of times the simulated roll of dice was 12: %d\n\n", rolls[10]); printf("The average of all simultaneous dice rolls is: %.3f", average); } //********************************* // USER DEFINED FUNCTION: roleDie // 'Random Number Generator' //********************************* int roleDie() { float result; int roll; result = rand(); roll = (result * 6) / 32768; return( roll + 1 ); }



LinkBack URL
About LinkBacks


