int TwoThrows();
int main(){
int Throws, Throw, Frequency[13]={0,0,0,0,0,0,0,0,0,0,0,0,0};
randomize();
cout << "\nThis program simulates throws of two dice.";
cout << "\n\nHow many throws : ";
cin >> Throws;
// Calls TwoThrows and saves in Frequency by value
for(int I=0; I<Throws; I++){
Throw=TwoThrows(); //2-12
Frequency[Throw]++; //2-12
}
// Prints array:
for(int I=0; I<11; I++){
cout << I+2 << ":\t" << Frequency[I+2] << "\n";
}
return 0;
}
int TwoThrows(){
unsigned int I=(random(6)+1)+(random(6)+1);
return I;
}
これは以下を出力します:
2: 1317 3: 2724 4: 4145 5: 5513 6: 7056 7: 8343 8: 6982 9: 5580 10: 4176 11: 2776 12: 1388
これは素晴らしいことです。
しかし、私が知りたいのは、なぜ配列を {0,0,0,0,0,0,0,0,0,0,0,0,0} に設定しなければならなかったのかということです。
そうしないと。私は得る:
2: 30626868 3: 1638233 4: 844545295 5: 1 6: 9 7: 4202510 8: 4199197 9: 844555757 10: 3 11: 4202574 12: 2130567168