... generation capabilities that were introduced in Section 6.9.

Figure 7.8 uses the array frequency (line 17) to count the occurrences of die value. The single statement in line 21 of this program replaces the entire switch statement in lines 22–43 of Fig. 6.7. Line 21 uses a random value to determine which frequency element to

Fig. 7.8 Die-rolling program using an array instead of switch.

Alternate View

 1   // Fig. 7.8: fig07_08.cpp
 2   // Die-rolling program using an array instead of switch.
 3   #include <iostream>
 4   #include <iomanip>
 5   #include <array>
 6   #include <random>
 7   #include <ctime>
 8   using namespace std;
 9
10   int main() {
11      // use the default ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.