Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By kaydell2

Thread: cash register program

  1. #1
    lanmonster is offline Member
    Join Date
    Dec 2012
    Posts
    22
    Rep Power
    0

    Default cash register program

    I am building a program that tells you what bills make up a certain amount. the amount is input by the user and manipulated in ways that need to be double. Here is the code I have. It does not work and I need some guidance from someone knowledgeable.
    Java Code:
            double tHundreds = 0;
            double tFifties = 0;
            double tTwenties = 0;
            double tTens = 0;
            double tFives = 0;
            double tOnes = 0;
            
            if (take >= 100){
                tHundreds = take % 100;
                take = take / 100;
            }
            if (take >= 50){
                tFifties = take % 50;
                take = take / 50;
            }
            if (take >= 20){
                tTwenties = take % 20;
                take = take / 20;
            }
            if (take >= 10){
                tTens = take % 10;
                take = take / 10;
            }
            if (take >= 5){
                tFives = take % 5;
                take = take / 5;
            }
            tOnes = take;
    take is the user input value that was declared previously.

  2. #2
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: cash register program

    Don't you think "It does not work" is a little too general for someone you expect to fix something?
    If you rip your car's engine from your car, get it to the repair center and tell them that something on your car "does not work", do you expect them to tell you why?
    I like likes!

  3. #3
    lanmonster is offline Member
    Join Date
    Dec 2012
    Posts
    22
    Rep Power
    0

    Default Re: cash register program

    Yes I do expect them to tell me what is wrong with my car. They are experts and they know what it is supposed to look like and they know what errors or imperfections look like. Also, your analogy is not relevant. I have ripped the 'engine' from my program and told you that the 'engine' doesn't work, not the whole program. Don't you think it would be impossible to diagnose an engine problem if you are not a mechanic or someone with knowledge in that field? Same applies here. I am in no way an expert and I don't have a clue why it doesn't work or what is wrong with it. Next time you make a snark comment, think it through. Better yet, instead of wasting your time and my time, HELP SOMEONE.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,000
    Blog Entries
    7
    Rep Power
    20

    Default Re: cash register program

    Swap the %s and /s and use ints for those bills (you can cast the values to double afterwards; the requirements don't make any sense).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    107
    Rep Power
    0

    Default Re: cash register program

    I wouldn't use doubles. I would use ints for this type of thing. I can't see the declaration of "take" but it should probably be an int too.
    DarrylBurke likes this.

  6. #6
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: cash register program

    Quote Originally Posted by lanmonster View Post
    Yes I do expect them to tell me what is wrong with my car. They are experts and they know what it is supposed to look like and they know what errors or imperfections look like.
    Don't you think it would be better to take the car to them and not just the engine that does not run like that even if it is ok? A mecahnic that cannot run the engine won't be able to tell you what is wrong and will shake his head for you disassembling the engine from the car...

    Next time you make a snark comment, think it through. Better yet, instead of wasting your time and my time, HELP SOMEONE.
    This is completly thought through, but obviously you do not understand it so I will make it clearer: Tell WHAT does not work. If you don't post a working piece of code you need to at LEAST tell what the symptoms are because no one can reproduce or wants to wase time to try to reproduce your error you do not describe.

    If you look at the comments you see "I can't see the declaration of "take" but it should probably be an int too" - the experts can do nothing more than wast guessing at what your problem might be at all!
    A proper description contains what you did, what you would expect and what really happens that makes you think that there is a problem. Easy example for you:
    - The input is 5
    - My expected output is 7 but the real output is 8

    This would be completly sufficient for a first answer. Snarling like you did moves you barely into the right direction... from what I can see I think your problem is simply that
    - you use the modulo operator and division incorrectly here (maybe as Josh said you confused the usage of them).
    - as has been said already your variables need to be integer.
    Last edited by Sierra; 01-06-2013 at 07:59 AM.
    I like likes!

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: cash register program

    Quote Originally Posted by lanmonster View Post
    Next time you make a snark comment, think it through. Better yet, instead of wasting your time and my time, HELP SOMEONE.
    Any more rudeness like that and you will be banned for a period. There will be no further warning.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    lanmonster is offline Member
    Join Date
    Dec 2012
    Posts
    22
    Rep Power
    0

    Default Re: cash register program

    Quote Originally Posted by kaydell2 View Post
    I wouldn't use doubles. I would use ints for this type of thing. I can't see the declaration of "take" but it should probably be an int too.
    when I try to use ints it does not compile and it tells me that there may be a loss of accuracy...

  9. #9
    Russd772 is offline Member
    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    0

    Default Re: cash register program

    im not too sure why it should be ints, maybe because of the use of the modulous ? is this program supposed to tell you how many of each bill is inside a certain value? so i input 150, it tells me that (1)$100 and (1)$50 bill are what you need to give me back? just a thought but if take is any number thats evenly divisible by these numbers your result would be 0. for example 100 would be in your first statement and take(100) % 100 = 0. now 0/100 = 0 so your answer would be incorrect. your problem here looks like mostly arithmatic but as Sierra said we cannot hope to help you unless you tell us what the actual error is that your getting

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,000
    Blog Entries
    7
    Rep Power
    20

    Default Re: cash register program

    Quote Originally Posted by lanmonster View Post
    when I try to use ints it does not compile and it tells me that there may be a loss of accuracy...
    Then you're trying to convert (say) a double to an int without telling the compiler that you know what you're doing; because you don't understand the error message, you don't know what you're doing ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Cash Register Class
    By FOX427 in forum New To Java
    Replies: 2
    Last Post: 06-30-2012, 09:31 PM
  2. Simple First Java program: Basic Contact register
    By ZinoXxX in forum New To Java
    Replies: 8
    Last Post: 03-17-2012, 03:13 PM
  3. Help with login and register program?
    By OllyHal in forum New To Java
    Replies: 3
    Last Post: 02-08-2012, 05:57 PM
  4. Cash Prize Challenge
    By Laura 123 in forum New To Java
    Replies: 19
    Last Post: 04-01-2009, 03:56 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
  •