converting money into all possible combinations









up vote
0
down vote

favorite












I know my question is repeated but I still couldn't understand what the other answers are explaining. Below is my code and I have calculated it to get to the first line which is 57 pennies + 0 dimes + 0 nickels + 0 quarters and I am thinking to run a loop that will list all the possible combinations of pennies, dimes, nickels, quarters. But, I don't know how.



public class Conversion
public static void main(String args)
int cents = 57;

int quarter = 25;
int dime = 10;
int nickel = 5;
int penny = 1;


int totalPennies = cents / penny;
cents %= penny;
int totalNickels = cents / nickel;
cents %= nickel;
int totalDimes = cents / dime;
cents %= dime;
int totalQuarters = cents / quarter;
cents %= quarter;


System.out.print(totalPennies + " pennies + ");
System.out.print(totalNickels + " nickels + ");
System.out.print(totalDimes + " dimes + ");
System.out.println(totalQuarters + " quarters");












share|improve this question



























    up vote
    0
    down vote

    favorite












    I know my question is repeated but I still couldn't understand what the other answers are explaining. Below is my code and I have calculated it to get to the first line which is 57 pennies + 0 dimes + 0 nickels + 0 quarters and I am thinking to run a loop that will list all the possible combinations of pennies, dimes, nickels, quarters. But, I don't know how.



    public class Conversion
    public static void main(String args)
    int cents = 57;

    int quarter = 25;
    int dime = 10;
    int nickel = 5;
    int penny = 1;


    int totalPennies = cents / penny;
    cents %= penny;
    int totalNickels = cents / nickel;
    cents %= nickel;
    int totalDimes = cents / dime;
    cents %= dime;
    int totalQuarters = cents / quarter;
    cents %= quarter;


    System.out.print(totalPennies + " pennies + ");
    System.out.print(totalNickels + " nickels + ");
    System.out.print(totalDimes + " dimes + ");
    System.out.println(totalQuarters + " quarters");












    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I know my question is repeated but I still couldn't understand what the other answers are explaining. Below is my code and I have calculated it to get to the first line which is 57 pennies + 0 dimes + 0 nickels + 0 quarters and I am thinking to run a loop that will list all the possible combinations of pennies, dimes, nickels, quarters. But, I don't know how.



      public class Conversion
      public static void main(String args)
      int cents = 57;

      int quarter = 25;
      int dime = 10;
      int nickel = 5;
      int penny = 1;


      int totalPennies = cents / penny;
      cents %= penny;
      int totalNickels = cents / nickel;
      cents %= nickel;
      int totalDimes = cents / dime;
      cents %= dime;
      int totalQuarters = cents / quarter;
      cents %= quarter;


      System.out.print(totalPennies + " pennies + ");
      System.out.print(totalNickels + " nickels + ");
      System.out.print(totalDimes + " dimes + ");
      System.out.println(totalQuarters + " quarters");












      share|improve this question















      I know my question is repeated but I still couldn't understand what the other answers are explaining. Below is my code and I have calculated it to get to the first line which is 57 pennies + 0 dimes + 0 nickels + 0 quarters and I am thinking to run a loop that will list all the possible combinations of pennies, dimes, nickels, quarters. But, I don't know how.



      public class Conversion
      public static void main(String args)
      int cents = 57;

      int quarter = 25;
      int dime = 10;
      int nickel = 5;
      int penny = 1;


      int totalPennies = cents / penny;
      cents %= penny;
      int totalNickels = cents / nickel;
      cents %= nickel;
      int totalDimes = cents / dime;
      cents %= dime;
      int totalQuarters = cents / quarter;
      cents %= quarter;


      System.out.print(totalPennies + " pennies + ");
      System.out.print(totalNickels + " nickels + ");
      System.out.print(totalDimes + " dimes + ");
      System.out.println(totalQuarters + " quarters");









      java






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 18:11

























      asked Nov 9 at 17:33









      sara99

      43




      43






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote













          Your order of operations is backwards.



          The first thing you do is count how many pennies you have. Since pennies are literally valued at 1, you can have 57 pennies and make up $0.57 just fine. That is obviously not what you want to accomplish.



          What you want to do is count from your highest denomination and work your way backwards. Here's a sample.



          // This should be the first operation
          int totalQuarters = cents / quarter;
          cents %= quarter;


          I leave reordering the rest as an exercise for the reader, but the output then becomes correct once successfully reordered.



          2 pennies + 1 nickels + 0 dimes + 2 quarters





          share|improve this answer




















          • But how do I output all the possible combinations?
            – sara99
            Nov 9 at 17:40










          • As I said before @sara99, the output you have is fine, but the order in which you calculate those values isn't. Just changing the order in which you do those operations will be enough to fix the issue.
            – Makoto
            Nov 9 at 17:41










          • Thank you, Mr. Makoto, I will fix that right now. So I don't have to run a loop for the other possible combinations?
            – sara99
            Nov 9 at 17:43










          • No, you do not require a loop. In this case that'd only make things worse.
            – Makoto
            Nov 9 at 17:44










          • I got exactly the same output but I needed other possible outcomes.
            – sara99
            Nov 9 at 17:51










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230711%2fconverting-money-into-all-possible-combinations%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote













          Your order of operations is backwards.



          The first thing you do is count how many pennies you have. Since pennies are literally valued at 1, you can have 57 pennies and make up $0.57 just fine. That is obviously not what you want to accomplish.



          What you want to do is count from your highest denomination and work your way backwards. Here's a sample.



          // This should be the first operation
          int totalQuarters = cents / quarter;
          cents %= quarter;


          I leave reordering the rest as an exercise for the reader, but the output then becomes correct once successfully reordered.



          2 pennies + 1 nickels + 0 dimes + 2 quarters





          share|improve this answer




















          • But how do I output all the possible combinations?
            – sara99
            Nov 9 at 17:40










          • As I said before @sara99, the output you have is fine, but the order in which you calculate those values isn't. Just changing the order in which you do those operations will be enough to fix the issue.
            – Makoto
            Nov 9 at 17:41










          • Thank you, Mr. Makoto, I will fix that right now. So I don't have to run a loop for the other possible combinations?
            – sara99
            Nov 9 at 17:43










          • No, you do not require a loop. In this case that'd only make things worse.
            – Makoto
            Nov 9 at 17:44










          • I got exactly the same output but I needed other possible outcomes.
            – sara99
            Nov 9 at 17:51














          up vote
          4
          down vote













          Your order of operations is backwards.



          The first thing you do is count how many pennies you have. Since pennies are literally valued at 1, you can have 57 pennies and make up $0.57 just fine. That is obviously not what you want to accomplish.



          What you want to do is count from your highest denomination and work your way backwards. Here's a sample.



          // This should be the first operation
          int totalQuarters = cents / quarter;
          cents %= quarter;


          I leave reordering the rest as an exercise for the reader, but the output then becomes correct once successfully reordered.



          2 pennies + 1 nickels + 0 dimes + 2 quarters





          share|improve this answer




















          • But how do I output all the possible combinations?
            – sara99
            Nov 9 at 17:40










          • As I said before @sara99, the output you have is fine, but the order in which you calculate those values isn't. Just changing the order in which you do those operations will be enough to fix the issue.
            – Makoto
            Nov 9 at 17:41










          • Thank you, Mr. Makoto, I will fix that right now. So I don't have to run a loop for the other possible combinations?
            – sara99
            Nov 9 at 17:43










          • No, you do not require a loop. In this case that'd only make things worse.
            – Makoto
            Nov 9 at 17:44










          • I got exactly the same output but I needed other possible outcomes.
            – sara99
            Nov 9 at 17:51












          up vote
          4
          down vote










          up vote
          4
          down vote









          Your order of operations is backwards.



          The first thing you do is count how many pennies you have. Since pennies are literally valued at 1, you can have 57 pennies and make up $0.57 just fine. That is obviously not what you want to accomplish.



          What you want to do is count from your highest denomination and work your way backwards. Here's a sample.



          // This should be the first operation
          int totalQuarters = cents / quarter;
          cents %= quarter;


          I leave reordering the rest as an exercise for the reader, but the output then becomes correct once successfully reordered.



          2 pennies + 1 nickels + 0 dimes + 2 quarters





          share|improve this answer












          Your order of operations is backwards.



          The first thing you do is count how many pennies you have. Since pennies are literally valued at 1, you can have 57 pennies and make up $0.57 just fine. That is obviously not what you want to accomplish.



          What you want to do is count from your highest denomination and work your way backwards. Here's a sample.



          // This should be the first operation
          int totalQuarters = cents / quarter;
          cents %= quarter;


          I leave reordering the rest as an exercise for the reader, but the output then becomes correct once successfully reordered.



          2 pennies + 1 nickels + 0 dimes + 2 quarters






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 17:37









          Makoto

          80.1k15125170




          80.1k15125170











          • But how do I output all the possible combinations?
            – sara99
            Nov 9 at 17:40










          • As I said before @sara99, the output you have is fine, but the order in which you calculate those values isn't. Just changing the order in which you do those operations will be enough to fix the issue.
            – Makoto
            Nov 9 at 17:41










          • Thank you, Mr. Makoto, I will fix that right now. So I don't have to run a loop for the other possible combinations?
            – sara99
            Nov 9 at 17:43










          • No, you do not require a loop. In this case that'd only make things worse.
            – Makoto
            Nov 9 at 17:44










          • I got exactly the same output but I needed other possible outcomes.
            – sara99
            Nov 9 at 17:51
















          • But how do I output all the possible combinations?
            – sara99
            Nov 9 at 17:40










          • As I said before @sara99, the output you have is fine, but the order in which you calculate those values isn't. Just changing the order in which you do those operations will be enough to fix the issue.
            – Makoto
            Nov 9 at 17:41










          • Thank you, Mr. Makoto, I will fix that right now. So I don't have to run a loop for the other possible combinations?
            – sara99
            Nov 9 at 17:43










          • No, you do not require a loop. In this case that'd only make things worse.
            – Makoto
            Nov 9 at 17:44










          • I got exactly the same output but I needed other possible outcomes.
            – sara99
            Nov 9 at 17:51















          But how do I output all the possible combinations?
          – sara99
          Nov 9 at 17:40




          But how do I output all the possible combinations?
          – sara99
          Nov 9 at 17:40












          As I said before @sara99, the output you have is fine, but the order in which you calculate those values isn't. Just changing the order in which you do those operations will be enough to fix the issue.
          – Makoto
          Nov 9 at 17:41




          As I said before @sara99, the output you have is fine, but the order in which you calculate those values isn't. Just changing the order in which you do those operations will be enough to fix the issue.
          – Makoto
          Nov 9 at 17:41












          Thank you, Mr. Makoto, I will fix that right now. So I don't have to run a loop for the other possible combinations?
          – sara99
          Nov 9 at 17:43




          Thank you, Mr. Makoto, I will fix that right now. So I don't have to run a loop for the other possible combinations?
          – sara99
          Nov 9 at 17:43












          No, you do not require a loop. In this case that'd only make things worse.
          – Makoto
          Nov 9 at 17:44




          No, you do not require a loop. In this case that'd only make things worse.
          – Makoto
          Nov 9 at 17:44












          I got exactly the same output but I needed other possible outcomes.
          – sara99
          Nov 9 at 17:51




          I got exactly the same output but I needed other possible outcomes.
          – sara99
          Nov 9 at 17:51

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230711%2fconverting-money-into-all-possible-combinations%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          政党