1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <time.h>
using namespace std;
int sum5(int n1, int n2, int n3, int n4, int n5)
{
return n1+n2+n3+n4+n5;
}
bool fiveOfAKind(int n1, int n2, int n3, int n4, int n5)
{
return (n1==n2 && n1==n3 && n1==n4 && n1==n5);
}
int main()
{
srand(time(NULL));
vector<int> diceRoll;
int n1=1,n2=2,n3=3,n4=4,n5=5;
while(!fiveOfAKind(n1,n2,n3,n4,n5))
{
n1 = rand()%6 +1;
n2 = rand()%6 +1;
n3 = rand()%6 +1;
n4 = rand()%6 +1;
n5 = rand()%6 +1;
diceRoll.push_back(sum5(n1,n2,n3,n4,n5));
}
int sumRoll = 0;
float avgRoll;
for(int i=0;i<diceRoll.size();i++)
{
sumRoll += diceRoll[i];
}
avgRoll = sumRoll*1.0/diceRoll.size();
cout<<"Number of rolls : "<<diceRoll.size()<<endl;
cout<<"Average value per roll : "<<avgRoll<<endl;
}
|