Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2005

Tip: Looking for answers? Try searching our database.

almost there!

Thread view: 
Michael - 29 Sep 2005 23:47 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.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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.