title: algorithm to simulate multiplication by addition (pseudo code)
body: <p>I'm trying to design an algorithm to simulate multiplication by addition. The input has to be, which can be zero, positive or negative.</p>
  
  <pre><code>if "a" &amp; "b" are two numbers 
  than
   if (a)(b)=ab or 2*4=8
  than a+a+a+a = ab or 2+2+2+2 =8
  </code></pre>
  
  <p>I have been given a question to solve and i cant figure it out yet. I've designed the following algorithm/pseudo-code:</p>
  
  <ol>
  <li>if C is a place where we have to store after addition and initially C=0</li>
  <li>add C into "a" and store in C (0+2=2)</li>
  <li>subtract 1 from "b" and store in "b". (4-1=3)</li>
  <li>if "b=0" STOP. otherwise goto step 2.</li>
  </ol>
  
  <p>While this algorithm work when <code>b &gt; 0</code>, it fails if <code>b</code> equals -1 or zero. The algorithm keeps running without ever stopping.</p>
  
  <p>How can I fix my algorithm so it works for negative numbers?</p>