#include #include #include #include using namespace std; int main() { random_device rnd; uniform_int_distribution d(0,2); int win_count = 0; for ( int i = 0; i < 1000000; ++i) { array a{0,0,0}; a.at(d(rnd)) = 1; // we always select box 0 if ( a.at(1) == 0 ) // host open box 1 if it's a goat win_count += a.at(2); // we switch to box 2 else // host open box 2 (must be goat since only one car) win_count += a.at(1); // we switch to box 1 } cout << setprecision(1) << fixed << "We win the car " << win_count/10000.00 << "% of the time if we switch." << endl; return 0; }