title: Making a console progress bar? (Windows)
body: <p>So I have a function (or rather, I'll turn it into a function later) to make a random % progress in a console window; like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;time.h&gt;
  #include &lt;cmath&gt;
  #include &lt;windows.h&gt;
  
  using namespace std;
  
  int main()
  {
      srand(time(0));
      int x = 0;
  
      for(int i = 0; i&lt;100; i++){
          int r = rand() % 1000;
          x++;
          cout &lt;&lt; "\r" &lt;&lt; x &lt;&lt; "% completed." &lt;&lt; flush;
          if(i &lt; 43){
             Sleep(r/6);
          }else if(i &gt; 43 &amp;&amp; i &lt; 74){
             Sleep(r/8);
          }else if(i &lt; 98){
             Sleep(r/5);
          }else if(i &gt; 97 &amp;&amp; i != 99){
             Sleep(2000);
          }
      }
  
      cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; "Operation completed successfully.\n" &lt;&lt; flush;
      return 0;
  }
  </code></pre>
  
  <p>The thing is, I want the output to be like this:</p>
  
  <pre><code>1% completed
  
  |
  </code></pre>
  
  <p>(later...)</p>
  
  <pre><code>25% completed
  
  |||||||||||||||||||||||||
  </code></pre>
  
  <p>How can I do that?</p>
  
  <p>Thanks in advance!</p>