(Dice Rolling with vector) Modify the dice-rolling program you created in Exercise 6.17 to use a vector to store the numbers of times each possible sum of the two dice appears.
What will be an ideal response?
```
#include
#include
#include
#include
#include
using namespace std;
int main()
{
const long ROLLS = 36000;
const int SIZE = 13;
// array expected contains counts for the expected
// number of times each sum occurs in 36 rolls of the dice
int expected[ SIZE ] = { 0, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1 };
int x; // first die
int y; // second die
vector< int > sum( SIZE );
srand( time( 0 ) );
// roll dice 36,000 times
for ( long i = 1; i <= ROLLS; i++ )
{
x = 1 + rand() % 6;
y = 1 + rand() % 6;
sum[ x + y ]++;
} // end for
cout << setw( 10 ) << "Sum" << setw( 10 ) << "Total" << setw( 10 )
<< "Expected" << setw( 10 ) << "Actual\n" << fixed << showpoint;
// display results of rolling dice
for ( int j = 2; j < SIZE; j++ )
cout << setw( 10 ) << j << setw( 10 ) << sum[ j ]
<< setprecision( 3 ) << setw( 9 )
<< 100.0 * expected[ j ] / 36 << "%" << setprecision( 3 )
<< setw( 9 ) << 100.0 * sum[ j ] / 36000 << "%\n";
} // end main
```
Sum Total Expected Actual
2 997 2.778% 2.769%
3 1982 5.556% 5.506%
4 3032 8.333% 8.422%
5 4064 11.111% 11.289%
6 4968 13.889% 13.800%
7 5927 16.667% 16.464%
8 5037 13.889% 13.992%
9 4014 11.111% 11.150%
10 2994 8.333% 8.317%
11 1990 5.556% 5.528%
12 995 2.778% 2.764%
You might also like to view...
The CSS3 _______ property configures the transparency of an element.
a. opacity b. transparency c. background-opacity d. opacity-background
A(n) ____________________ is a separate HTML document that defines the structure and properties of a Web page with frames.
Fill in the blank(s) with the appropriate word(s).
A PC is a collection of software and data components that help you accomplish many different tasks.
Answer the following statement true (T) or false (F)
____ peripheral devices are assigned to only one job at a time.
A. Dedicated B. Shared C. Virtual D. Static