samedi 7 février 2015

countimg the number of times that the sum of two dice appear

I want to see the number of times that the sum of two rolling dice appear. I'm writing the following code to show me the sum with myArray:



#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
srand (time(0));

int myArray[12];

for (int i =1; i < 10; i++)
{
int die_1 = rand() % 6 + 1;
int die_2 = rand() % 6 + 1;

myArray[(die_1 + die_2 - 2)]++;


cout<<endl<<"die_1 "<<die_1<<" die_2 "<<die_2<<" the sum: "<<die_1+die_2;
}

for (int i = 0; i < 12; i++)
cout<<endl<<myArray[i]<<" ";
}


but the code is returning weird results to me. Would appreciate any help to correct it.





Aucun commentaire:

Enregistrer un commentaire