title: C++ How to convert decimal number to binary?
body: <p>I was tasked with writing some code that will take a user input and convert the number to its binary number. I have written some code so far, but am having one issue. I have to use a for loop and the quotient-remainder method. When I output the remainder(binary), it is not printing the last digit.</p>
  
  <p>The question I'm asking is: What would I have to change in my for loop to make it print out the last digit of the binary number? </p>
  
  <pre><code>int main()
  {
      int num;
      int rem;
  
      cout &lt;&lt; "Please enter a number: ";
      cin &gt;&gt; num;
  
      for (int i = 0; i &lt;= (num + 1); i++)
      {
          num /= 2;
          rem = num % 2;
          cout &lt;&lt; rem;
      }
  
      _getch();
      return 0;
  } 
  </code></pre>
  
  <p>Any help is appreciated, Thank you!</p>