title: C++ Converting a while loop to a do-while loop
body: <p>I see a ton a questions for converting for loops to while and do while loops, but I cant seem to find anything on converting while loops to do while loops in C++. It still needs to maintain the same function as the original code as well.</p>
  
  <p>Here is the original code:</p>
  
  <pre><code>int number, product = 1, count = 0; 
  
  cout &lt;&lt; "Enter a whole number to be included in the product" 
  &lt;&lt; endl &lt;&lt; "or enter 0 to end the input: "; 
  cin &gt;&gt; number; 
  
  while (number != 0) 
  {
  product = product * number; 
  count++; 
  cout &lt;&lt; "Enter a whole number to be included in the product" 
  &lt;&lt; endl &lt;&lt; "or enter 0 to end the input: "; 
  cin &gt;&gt; number; 
  } 
  
  if (count &gt; 0) 
  { 
  cout &lt;&lt; endl &lt;&lt; "The product is " &lt;&lt; product &lt;&lt; "." &lt;&lt; endl; 
  } 
  </code></pre>
  
  <p>By moving it around, I was able to end up here, but I keep ending up with errors. <strong>When I run the program, it prompts me to enter a while number, like expected. If I enter a valid number, it loops and asks me the same question. Then when I enter 0, it kicks out as usual, but it displays that the product is 0 no matter the numbers entered before.</strong></p>
  
  <p>Here is my attempt at adjusting it into a do while loop:</p>
  
  <pre><code>int main()
  {   
  
  int number, product = 1, count = 0; 
  
  do
  {
      cout &lt;&lt; "Enter a whole number to be included in the product" &lt;&lt; endl &lt;&lt; "or enter 0 to end the input: "; 
      cin &gt;&gt; number; 
      product = product * number; 
      count++; 
  }
  
  while (number != 0);
  {
      if (count &gt; 0) 
      cout &lt;&lt; endl &lt;&lt; "The product is " &lt;&lt; product &lt;&lt; "." &lt;&lt; endl; 
  }
  }
  </code></pre>