Q F

Q F

  • NA
  • 5
  • 5.8k

Monty Hall Problem, Something wrong with counter

Oct 2 2012 4:25 PM

int main()
{
    srand(time(0));
    int counter = 100000;
    int WinSwitchCounter = 0;
    int WinStayCounter = 0;
    int decision;

    cout << "Number of Times Staying Was The Correct Strategy: "
        << WinStayCounter << endl;
    cout << "Number of Times Switching Was The Correct Strategy:"
        << WinStayCounter << endl;

    for (int decision = 0; decision <= counter; ++decision)
    {
        int prize_door = (rand() % 3 + 1);//random choice from 1-3
        int stay_choice = (rand() % 3 + 1);
        int switch_choice = (rand() % 2 + 1);

        if (stay_choice == prize_door)
        {
            ++WinStayCounter;
        }
        else if (switch_choice == prize_door)
        {
             ++WinSwitchCounter;
        }
//Compare Stay to Switch to determine best strategy
         if (WinStayCounter > WinSwitchCounter)
         {
             cout << "Therefore, the best thing to do is to Stay " << endl;
         }
         else
         {
             cout << "Therefore, the best thing to do is to Switch " << endl;
         }
    return 0;
    }
}

v


Answers (3)