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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <time.h>
using namespace std;
int main()
{
unsigned seed = time(0);
int dice1, dice2;
int total;
int sum2 = 0, sum3 = 0, sum4 =0, sum5 = 0, sum6 = 0, sum7 = 0, sum8 = 0, sum9 = 0, sum10 = 0, sum11 = 0, sum12 = 0;
int SIZE = 10;
int sums[SIZE] = {sum2, sum3, sum4, sum5, sum6, sum7, sum8, sum9, sum10, sum11, sum12};
srand(seed);
for (int t = 0; t < 2; t++)
{
dice1 = (rand() % 6) + 1;
dice2 = (rand() % 6) + 1;
total = dice1 + dice2;
cout << total;
if (total = 2)
sum2++;
else if (total = 3)
sum3++;
else if (total = 4)
sum4++;
else if (total = 5)
sum5++;
else if (total = 6)
sum6++;
else if (total = 7)
sum7++;
else if (total = 8)
sum8++;
else if (total = 9)
sum9++;
else if (total = 10)
sum10++;
else if (total = 11)
sum11++;
else if (total = 12)
sum12++;
}
cout << "The sum of 2 appeared " << sum2 << " times." << endl;
cout << "The sum of 3 appeared " << sum3 << " times." << endl;
cout << "The sum of 4 appeared " << sum4 << " times." << endl;
cout << "The sum of 5 appeared " << sum5 << " times." << endl;
cout << "The sum of 6 appeared " << sum6 << " times." << endl;
cout << "The sum of 7 appeared " << sum7 << " times." << endl;
cout << "The sum of 8 appeared " << sum8 << " times." << endl;
cout << "The sum of 9 appeared " << sum9 << " times." << endl;
cout << "The sum of 10 appeared " << sum10 << " times." << endl;
cout << "The sum of 11 appeared " << sum11 << " times." << endl;
cout << "The sum of 12 appeared " << sum12 << " times." << endl;
return 0;
}
|