#include using std::cout; using std::cin; using std::endl; using std::fixed; #include using std::setw; using std::setprecision; #include #include int main() { const long ROLLS = 36000; int thesum[13] = {0}; double sum[13] = {0}; double expected[13]= {0}; int die1; int die2; srand( time( 0 ) ); for ( int roll = 1; roll <= ROLLS; roll++) { die1 = (1 + rand() % 6); die2 = (1 + rand() % 6); ++sum[(die1 + die2)]; ++thesum[(die1 + die2)]; } for (int row = 1; row <=6; row++) { for (int column = 1; column <= 6; column++) { ++expected[row + column]; } } cout << setw(10) << "Sum" << setw(10) << "Total" << setw(10) << "Expected" << setw(10) << "actual\n" << fixed << setprecision(3); for (int j = 2; j < 13; ++j) cout << setw(10) << j << setw(10) << thesum[j] << setw(9) << 100.0 * expected[j] / 36 << "%" << setw(9) << 100 * sum[j] / ROLLS << "%\n"; return 0; }