Posted: Thu Oct 16, 2008 5:14 pm Post subject: Conversion Error
This program is supposed to convert a number of pennies into dollars and cents. It's not. ill post the code, and if anyone can find the flaw... I'd appreciate learning what i did wrong. Also, you need to run the read.java file BEFORE trying converter.java. the reason is that my statements for string input are in the read.java file.
Posted: Thu Oct 16, 2008 6:13 pm Post subject: RE:Conversion Error
no not really. but it is good to be prepared for any eventuality. and pennies is a string, not a int. so div and mod won't work
edit: thanks tony. i realise that my code says if the Length of the STRING is greater than 10, etc what i needed it to say was if the number of pennies is greater than 9999....
edit 2: what do you mean by mod? the dollars seems to work fine by i can't get pennies to work
Tony
Posted: Thu Oct 16, 2008 7:42 pm Post subject: Re: RE:Conversion Error
Posted: Fri Oct 17, 2008 9:00 am Post subject: RE:Conversion Error
A\V, you will want to convert the String value to an integer value. Try using Integer.parseInt(). Then you'll have an int value to work with, so division and modulus will work, as per Tony's post.
Insectoid
Posted: Fri Oct 17, 2008 11:12 am Post subject: RE:Conversion Error
Div will return the number of times a number can be divided into a number. Div in java is just '/'. so,
code:
this = that/foo
where 'that' and 'foo' are integers. Basically, Java divides them and cuts of the decimal.