title: The name does not exist in the current context when using an if statement
body: <p>I want to calculate Pi with the number of decimal places given by the user and when the input is 0 the variable piNumber should be set to '3' and not '3,' so that the output doesn't have a useless comma.</p>
  
  <p>This works</p>
  
  <pre><code>        static string PiNumberFinder(int amountOfDigits)
      {
          string piNumber = "3,";
          int dividedBy = 11080585;
          int divisor = 78256779;
          int result;
          for (int i = 0; i &lt; amountOfDigits; i++)
          {
              if (dividedBy &lt; divisor)
                  dividedBy *= 10;
  
              result = dividedBy / divisor;
  
              string resultString = result.ToString();
              piNumber += resultString;
  
              dividedBy = dividedBy - divisor * result;
          }
  
          return piNumber;
      }
  </code></pre>
  
  <p>But with the if statement it doesn't</p>
  
  <pre><code>        static string PiNumberFinder(int amountOfDigits)
      {
          int dividedBy = 11080585;
          int divisor = 78256779;
          int result;
          if (amountOfDigits == 0)
          {
              string piNumber = "3";
          }
          else
          {
              string piNumber = "3,";
          }
          for (int i = 0; i &lt; amountOfDigits; i++)
          {
              if (dividedBy &lt; divisor)
                  dividedBy *= 10;
  
              result = dividedBy / divisor;
  
              string resultString = result.ToString();
              piNumber += resultString;  // I get an error here
  
              dividedBy = dividedBy - divisor * result;
          }
  
          return piNumber;  // I get an error here
      }
  </code></pre>
  
  <p>I get the error "The name 'piNumber' does not exist in the current context" twice for the lines pointed in the code above</p>