Determining the difference between the actual percentages of occurrences and the true probabilistic values.

so far all i gotten was to show how many times it occurred but some of them are coming back in the thousands or the millions when the array was set to 100 times.

#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main(){
int dice[100];
int d1,d2,tot;
srand(time(0));
cout<<"ROLLS"<<endl;

for(int i=1; i<=100; i++){
d1=1+rand()%6;
d2=1+rand()%6;
tot= d1 + d2;
dice[tot]++;
cout<<tot<<endl;
}
cout<<"----------------------------------"<<endl;

for(int n=2; n<=12; n++){
cout<<"roll= "<<n<<" occurred "<<dice[n]<<" times "<<endl;
}
return 0;
}
Last edited on
int dice[100] = {};
initialize your variables.
Note: that array can hold 100 elements, but only the first 13 are needed.

Please use code tags (and intuitive/systematic indentation) when posting code.
See http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.