title: Question about the What's In the Box code game assignment
body: <p>I am struggling to understand how to properly use pass by value and reference in this program. It keeps saying identifier is undefined when I put the Int in the main function. But when it's out of the main function it works fine. I can't use it outside of the main function otherwise it's an automatic 0. Am I just missing code that identifies it? </p>
  
  <p>I didn't explain the program very well. It's essentially the Monty Hall problem but with boxes. The user then tries to guess the right box. The biggest issue I had was getting the non prize box to appear to the user in the output.</p>
  
  <p>I am very new to coding so I am probably overlooking something.</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  
  #include &lt;iomanip&gt;
  
  #include &lt;iostream&gt;
  
  #include &lt;time.h&gt;
  
  #include &lt;string&gt;
  
  using namespace std;
  </code></pre>
  
  <p>/*******************************************************************************
  *  Function Name: main()
  *  Parameters: None
  *  Return Value: int
  *  Purpose: To execute the main function of the program. Performs loops and takes user input to execute the game.
  *****************************************************************************/</p>
  
  <pre><code>void BoxCheck(int);
  
  void PrizeBox(int&amp;);
  
  //int UserGuess = 0;
  
  
  
  
  
  
  int main()
  {
  
      int UserChoice;
  
      int UserGuess;
  
      int BoxReveal;
  
      int PrizeB;
  
     // int Prize;
  
     //char Switch;
  
  
     cout &lt;&lt; "Wellcome to Pandora's Prize!" &lt;&lt; endl;
  
     cout &lt;&lt; "Infront of you there are three doors, and behind one of them is the grand prize!" &lt;&lt; endl;
  
     cout &lt;&lt; "But in the the other two they contain a stink bomb." &lt;&lt; endl;
  
     cout &lt;&lt; "It's your job to guess which one has the prize behind it." &lt;&lt; endl;
  
     cout &lt;&lt; "Door 1?" &lt;&lt; endl;
  
     cout &lt;&lt; "Door 2?" &lt;&lt; endl;
  
     cout &lt;&lt; "Door 3?" &lt;&lt; endl;
  
     PrizeBox(PrizeB);
  
  
     cin &gt;&gt; UserGuess;
  
     BoxReveal != (PrizeB || UserGuess);
  
  
  
      // cout &lt;&lt; "The host revealed box number " &lt;&lt; BoxReveal &lt;&lt; " ." &lt;&lt; endl;
      //if (true)
      //{
      if (UserGuess == 1)
      {
          cout &lt;&lt; "You picked box 1." &lt;&lt; endl;
  
  
  
          cout &lt;&lt; "The host revealed box number " &lt;&lt; BoxReveal &lt;&lt; " ." &lt;&lt; endl;
  
  
  
          cout &lt;&lt; "Would you like to stay with box number 1 or switch." &lt;&lt; endl;
  
  
  
          //cin &gt;&gt; UserChoice;
  
      }
  
      else if (UserGuess == 2)
      {
         cout &lt;&lt; "You picked box 2." &lt;&lt; endl;
  
  
  
          cout &lt;&lt; "The host revealed box number " &lt;&lt; BoxReveal &lt;&lt; " ." &lt;&lt; endl;
  
  
  
          cout &lt;&lt; "Would you like to stay with box number 2 or switch." &lt;&lt; endl;
  
  
  
          //cin &gt;&gt; UserChoice;
  
      }
  
      else if (UserGuess == 3)
      {
          cout &lt;&lt; "You picked box 3." &lt;&lt; endl;
  
  
  
          cout &lt;&lt; "The host revealed box number " &lt;&lt; BoxReveal &lt;&lt; " ." &lt;&lt; endl;
  
          cout &lt;&lt; "It contains a red snapper!" &lt;&lt; endl;
  
          cout &lt;&lt; "Would you like to stay with box number 3 or switch." &lt;&lt; endl;
  
          //cin &gt;&gt; UserChoice;
  
  
      }
  
      else
      {
  
          cout &lt;&lt; "This isn't a number associated with a box. Try again." &lt;&lt; endl;
  
  
  
      }
  
      //}
  
      /* if (true)
      {
  
      } */
  
  
      //PrizeBox(Prize);
      if (UserChoice == UserGuess)
      {
          cout &lt;&lt; "You chose to stay with your original box." &lt;&lt; endl;
  
          BoxCheck(UserGuess);
      }
  
  
  
      else if (UserChoice != UserGuess)  //|| UserChoice != BoxReveal)
      {
          cout &lt;&lt; "You decided to switch." &lt;&lt; endl;
  
          BoxCheck(UserGuess);
      }
  
  
  
       /*else if (UserChoice != UserGuess || BoxReveal)
      {
          cout &lt;&lt; "You decided to switch." &lt;&lt; endl;
  
          BoxCheck(UserGuess);
      } */
  
      else
      {
          cout &lt;&lt; "Your answer was out of the parameters." &lt;&lt; endl;
  
          BoxCheck(UserGuess);
      } 
  
  
      //BoxCheck(UserGuess);
  
      system("pause");
  
      return 0;
  
  }
  
  
  
  void PrizeBox(int&amp; PrizeB)
  {
      srand(time(NULL));
  
      PrizeB = rand() % 3 + 1;
  
      //Prize = rand() % 3 + 1;
  
      //cin &gt;&gt; PrizeB;
  
      /* BoxReveal = !(PrizeBox || boxChoice);
      cout &lt;&lt; "Here is one of the box's opened! " &lt;&lt; boxReveal &lt;&lt; " ." &lt;&lt; endl;
      BSwitch = (boxChoice || boxReveal); */
  
  
  
  
  }
  
  
  void BoxCheck(int UserChoice)
  {
      if (UserChoice == PrizeB)
      {
          cout &lt;&lt; "WOW YOU WON!!!!" &lt;&lt; endl;
      }
  
      else if (UserChoice != PrizeB)
      {
          cout &lt;&lt; "Sorry you got a red snapper" &lt;&lt; endl;
      }
  
      else
      {
          cout &lt;&lt; "Sorry you got a red snapper" &lt;&lt; endl;
      }
  }   
  </code></pre>