title: Modulus of an integer
body: <p>I'm writing a program that gets a dollar amount from input and displays the amount in words. Unable to use strings, arrays, or functions at this point, so I've worked it out with switch structures, though it's not very efficient.</p>
  
  <p>However my problem comes with when I've converted the input from a float to an integer, and trying to single out the digits after the decimal point using modulus; for some reason it doesn't return the correct digit.</p>
  
  <p>So say for 321.78
  extracting the 1st decimal(or 8) it returns a 7. I'm not too sure why this happens, and how too fix it.</p>
  
  <p>Here is my code for the first part</p>
  
  <pre><code>float number;
  int digit1, digit2, digit3, decimals, decimal1, decimal2, int_number;
  
  cout &lt;&lt; "Enter a dollar amount from 0-1000: ";
  cin &gt;&gt; number;
  
  int_number = number * 100;
  
  digit1 = (int_number % 1000)/100; //ones
  digit2 = (int_number % 10000)/1000; //tens
  digit3 = (int_number % 100000)/10000; // hundreds
  
  decimal1 = int_number % 10;
  decimal2 = (int_number % 100)/10;
  </code></pre>
  
  <p>The decimal1 should return a 8 if input is 321.78. Have I missed something?
  Any help would be appreciated.</p>