title: Conversion from millimeter to km (with overflow in smaller units e.g. m)
body: <p>I need to write the program in c++, which converts mm units to km, m, cm and mm. In other words on input of, for instance, 7580341 mm it should output 7580341mm equals 7km 580m 34cm 1mm. I'm getting 7km 6m 34cm 1mm instead. I did something wrong with modulo function and I can't figure it out. Why does it calculate correct values with cm and mm, but not with m? Please help.</p>
  
  <p>All the best</p>
  
  <p>Pavle</p>
  
  <pre><code>int mm, cm, m, km;
  cout &lt;&lt; "Type in value in millimeter:\n";
  cin &gt;&gt; mm;
  
  cm = mm/10;
  m = mm/1000;
  km = mm/1000000;
  
  cout &lt;&lt; mm &lt;&lt; "mm equals " &lt;&lt; km &lt;&lt; "km " &lt;&lt; m%km &lt;&lt; "m " &lt;&lt; cm%m &lt;&lt; "cm " &lt;&lt; mm%cm &lt;&lt; "mm\n";
  
  return 0;
  </code></pre>