Hello, I was wondering if anyone could tell me how I can get cents. I can
get dollars fine but not the right amount of cents.For example, if i input
100 20 10 4 1 1 (pennies,nickels,dimes,quarters,loonies,toonies) i should
get 7 dollars and 0 cents. but i get
Please enter the number of pennies, nickels, dimes, quarters, loonies,
toonies,
each separated by a single space.
100 20 10 4 1 1
7 dollar(s) and 700 cents
Press any key to continue . . .
my code is
// Convert strings to integer values.
int pen1 = Integer.parseInt(pen);
int nick1 = Integer.parseInt(nick);
int dime1 = Integer.parseInt(dime);
int quart1= Integer.parseInt(quart);
int loon1 = Integer.parseInt(loon);
int toon1 = Integer.parseInt(toon);
// Calculates the total cent value.
int coins= (pen1*1) + (nick1*5) + (dime1*10) + (quart1*25)
+ (loon1*100) + (toon1*200);
// Calculate the total dollar value.
int dollars=(coins/100);
System.out.println(dollars +" "+ "dollar(s) " + "and " + coins + " " +
"cents"); // Prints out total money value.
}
}
klynn47@comcast.net - 30 Sep 2005 00:00 GMT
Use %
Michael - 30 Sep 2005 00:04 GMT
Thanks I already figured it out I used the remainder modulus. But thank you
for responding...
> Use %
Roedy Green - 30 Sep 2005 01:17 GMT
>Hello, I was wondering if anyone could tell me how I can get cents. I can
>get dollars fine but not the right amount of cents.
See http://mindprod.com/jgloss/currency.html
also http://mindprod.com/jgloss/modulo.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.