CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2009
    Posts
    2

    Code help, Please

    Hey... I am making a change maker program. What it is supposed to do is ask how much an item was, then ask how much they are going to pay with. Then it will give the person the correct amount of change. It's supposed to keep running until a negative amount is returned.

    My problem is...
    When the person enters the amount the item was the would put it in like ##.## BUT java won't recognize the cent value. SO i have Enter Dollar amount, and then enter Cent amount. I need to be able to convert ##.## to work in my program instead of the way I have it.


    Any help will be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Join Date
    May 2005
    Location
    San Antonio Tx
    Posts
    44

    Re: Code help, Please

    you are using int instead of double to read the user input.

    replace your int declarations
    Code:
    int dollars = 0;
    double dollars = 0.0;
    by doing the proper math you should be able to separate whole numbers from decimals and and you'll have your dollars and cents.
    you may also want to use the round function from the java library

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured