title: Money counter C program
body: <p>I have generated code that counts the minimum number of 20's, 10's, 5's, 2's and 1's that will  add up to a user defined amount of money. The user is only allowed to enter whole numbers i.e. no decimal values. I have two questions.</p>
  
  <ol>
  <li>If a denomination is not needed, the program outputs a random number instead of 0. How can I fix this?</li>
  <li>Is it possible to create a function that could replace all of the if statements and possibly the <code>printf</code> statements? I'm new to functions so am a little bit lost with them.</li>
  </ol>
  
  <p></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void)
  {
   int pounds;
   int one, two, five, ten, twenty;
  
      printf("Enter a pounds amount with no decimals, max E999999: \n");
      scanf("%d", &amp;pounds);
      printf("%d\n", pounds);
  
      if(pounds &gt;= 20)
      {
          twenty = (pounds / 20);
          pounds = (pounds-(twenty * 20));
          printf("%d\n", pounds);
      }
      if(pounds &gt;= 10)
      {
          ten = (pounds / 10);
          pounds = (pounds-(ten * 10));
          printf("%d\n", pounds);
      }
      if(pounds &gt;= 5)
      {
          five = (pounds / 5);
          pounds = (pounds-(five * 5));
          printf("%d\n", pounds);
      }
      if(pounds &gt;= 2)
      {
          two = (pounds / 2);
          pounds = (pounds-(two * 2));
          printf("%d\n", pounds);
      }
      if(pounds &gt;= 1)
      {
          one = (pounds / 1);
          pounds = (pounds-(one * 1));
          printf("%d\n", pounds);
      }
  
  
   printf("The smallest amount of denominations you need are: \n");
   printf("20 x %d\n", twenty);
   printf("10 x %d\n", ten);
   printf("5 x %d\n", five);
   printf("2 x %d\n", two);
   printf("1 x %d\n", one);
  
  return 0;
  }
  </code></pre>