Results 1 to 7 of 7
  1. #1
    Tommeke is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default help needed plz with some loop problem I guess

    Hi, I have a problem.
    I have to solve a problem, but I cant seem to work it out.
    I have to give change to some amount.
    I tried some loop things but I cant seem to make it work.
    the problem is that I have to give back "money"( only in values of 50, 20 and 10) to any amount.
    for example if someone types in 90 I have to give back 1x50, 2x20. if some one type in the number 96 the machine rounds up to 100 and have to give back 2x50. if someone types in 130 it will be 2x50, 1x20 and 1x10 so I always have to give back the highest possible value (50 , 20 or 10)
    Can someone help me plz!!!

    thnx

    T

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default

    Please see the link in my signature on asking questions the smart way before posting again.

    You haven't provided any information that we can use to help you- create an SSCCE (that does NOT mean paste in your entire program) that demonstrates what you're talking about, be specific, and we'll go from there. You saying "I tried some loop things but I can't seem to make it work" is as useful to us as us saying "then try some other loop things that do work" is useful to you.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Tommeke is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default

    I'm sorry.
    this is what I tried already


    public class Money {

    public static void main (String args[]) {

    int inputAmnt = Integer.parseInt(args[0]);
    int amnt50 = 50;
    int amnt20 = 20;
    int amnt10 = 10;
    int rest;

    System.out.println("Input amount = " + inputAmnt);
    while(amnt50 <= inputAmnt){
    int rest1 = inputAmnt - amnt50;
    System.out.println(" u krijgt 1 x 50 ");
    while (amnt20 <= rest1){
    int rest2 = rest1 - amnt20;
    System.out.println(" u krijgt 1 x 20 ");
    while (amnt10 <= rest2){
    int rest3 = rest2 - amnt10;
    System.out.println(" u krijgt 1 x 10 ");
    }
    }
    }
    }
    }

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default

    You forgot the code tags.

    And what does that code do? What did you expect it to do? What happened when you stepped through it with a debugger?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Tommeke is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default

    well...this discribes my problem quit well no? :s
    I'm using notepad++ by the way.
    I don't know how tho explaine it otherwise.
    I have the mathematical problem that I have to solve. but that is easy, but I don't know how to write it in code...
    I tried this because it calculates how for example how many times 50goes into 90, that is one, and then you get 40 and then have to calculate how many times 20 goes into 40, 2 time, but then the code gets into an infinite loop there.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    then the code gets into an infinite loop
    What controls the looping? Is there some variable's value that keeps the code in the loop? Can you change that value so that the loop will exit?
    If you don't know how the values are changing in the loop, add a println to print out the values of ALL the variables used in that loop. Looking at the output should show you where they are not being changed as they need be.

  7. #7
    Tommeke is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks for the fast replies, but I finally got it!! yes:p
    the while loops where nested in each other apparently :s
    when I sepperated them it worked!! now I have to trie to write classes for each note...back to work :)
    it's fun, but I find it very difficult to see all this.

Similar Threads

  1. guess game GUI
    By tomandhisjones in forum New To Java
    Replies: 4
    Last Post: 04-04-2011, 06:30 AM
  2. Easy Thing I Guess ...
    By loopsnhoops in forum New To Java
    Replies: 1
    Last Post: 02-24-2011, 10:37 PM
  3. Guess Character
    By pinkdreammsss in forum Java Applets
    Replies: 14
    Last Post: 05-05-2010, 07:28 PM
  4. resultset.next() = false ;; Can't Guess why.. please help.
    By Stephen Douglas in forum New To Java
    Replies: 11
    Last Post: 04-12-2010, 10:21 AM
  5. guess number game
    By mistah in forum New To Java
    Replies: 10
    Last Post: 11-23-2008, 03:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •