title: Java, displaying change in coins, arrays, functions?
body: <p>My function ReturnChange is supposed to take in change, coins array (int Coins[] = {100, 50, 20, 10, 5};) p.s they are in cents,  and numCoins array (int NumCoins[] = {10, 10, 10, 10, 10};) and calculate the change. The change should be in coins. If coins finish i.e num coins than alternative coins have to be used. </p>
  
  <pre><code>private static int ReturnChange(double change, int[] Coins, int[] numCoins) {
  
      int i = 0;
      int totalcoins = 0;
      change = change * 100;
      do {
  
          totalcoins++;
          change -= 100;
  
      } while (change &gt;= 100);
      System.out.println("1 dollar x " + totalcoins + "");
      i++;
      int coinsfifty = 0;
      do {
          coinsfifty++;
          change -= 50;
  
      } while (change &gt;= 50);
      System.out.println("50 cents x " + coinsfifty + "");
      i++;
      int coinstwenty = 0;
      do {
          coinstwenty++;
          change -= 20;
  
      } while (change &gt;= 20);
      System.out.println("20 cent x " + coinstwenty + "");
      i++;
      int coinsten = 0;
      do {
          coinsten++;
          change -= 10;
  
      } while (change &gt;= 10);
      System.out.println("10 cent x " + coinsten + "");
      i++;
      int coinsfive = 0;
      do {
  
          coinsfive++;
          change -= 5;
      } while (change &gt;= 5);
      System.out.println("5 cent x " + coinsfive + "");
      return 0;
  
  }
  </code></pre>
  
  <p>the output when 4 is passed as change is :</p>
  
  <blockquote>
    <p>1 dollar x 4<br>
    50 cents x 1<br>
    20 cent x 1<br>
    10 cent x 1<br>
    5 cent x 1</p>
  </blockquote>
  
  <p>the output when 2.5 as example is passed in change:</p>
  
  <blockquote>
    <p>1 dollar x 2<br>
    50 cents x 1<br>
    20 cent x 1<br>
    10 cent x 1<br>
    5 cent x 1</p>
  </blockquote>
  
  <p>The problem:
  Need the others such as 50 cents etc to display zero in output 1, and display 0 for 20 cent onwards in output 2 and not one.</p>