title: Converting a decimal number to binary in c++
body: <p>this code finds the binary of a decimal integer N; it divides the number by 2 and takes the floor of the result and divides it also by 2,<br>
  the code gets the remainder of those divisions 0 or 1 and builds up the binary.</p>
  
  <p>The problem with this code is that it won't run until the last division example (take 128 the last division is 1/2 and remainder is 1, the program stops at <code>N/2 &gt; 0</code> as specified in the while loop and <code>1/2 = 0</code> since 1 is of type int).</p>
  
  <p>How do I resolve this issue or how do I modify the condition in the while loop?</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  void ConvertToBinary(int N);
  int main()
  {
      int N = 1;
      while (1)
      {
          cout &lt;&lt; "enter N: ";
          cin &gt;&gt; N;
          cout &lt;&lt; endl;
          ConvertToBinary(N);
          cout &lt;&lt; endl;
      }
      system("pause");
      return 0;
  }
  void ConvertToBinary(int N)
  {
      int A[1000];
      int i=0;
      cout &lt;&lt; "The binary of " &lt;&lt; N &lt;&lt; "= ";
      while (N / 2 &gt; 0)
      {
          if (N % 2 == 0)
          {
              A[i] = 0;
          }
          else if (N % 2 != 0)
          {
              A[i] = 1;
          }
          N = N / 2;
          i++;
      }
      for (int j= i-1 ; j&gt;=0 ; j--)
      {
          cout&lt;&lt;A[j];
      }
  
  
      cout &lt;&lt; endl;
  
  }
  </code></pre>