/*------------------------------------------------------------------*/ /* Problem chapter5_15 */ /* */ /* This program simulates rolling two six-sided "fair" dice. */ /* The user enter the number of rolls. */ #include #include #include using namespace std; int rand_int(int a, int b); int main() { /* Declare variables and function prototypes. */ int count=0, total=0; /* Prompt user for number of rolls. */ cout << "\n\nEnter number of fair pair-dice rolls: "; cin >> total; /* Roll the die as many times as required */ srand(time(NULL)); for (int rolls=1; rolls <= total; rolls++) if ( rand_int(1,6) + rand_int(1,6) == 8 ) count++; /* Print the results. */ cout << "\nNumber of rolls: " << total << endl; cout << " Percentage where the sum is eight: " << 100.0*count/total << endl; /* Exit program. */ return 0; } /*------------------------------------------------------------------*/ /* (rand_int function from page 185) */ /* This function generates a random integer */ /* between specified limits a and b (a