Click to See Complete Forum and Search --> : Code help, Please


anw5238
December 8th, 2009, 09:18 AM
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.

mrjavoman
December 8th, 2009, 02:55 PM
you are using int instead of double to read the user input.

replace your int declarations

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