Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 outputing change in denominations
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rated




PostPosted: Wed Sep 24, 2008 5:08 pm   Post subject: outputing change in denominations

Hi, I have to write a program that will output a receipt showing purchased price, taxes, total, amount paid and change. I did that part.

But what do I have to do so that my program will output the change in denominations (e.g. change is $8.04 - output exact dominations, that is to say, one $5 bill, a toonie, quarters.etc)?
How do I do that using the modulus %operator?

thanks!.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed Sep 24, 2008 6:22 pm   Post subject: RE:outputing change in denominations

I did this last year. It was pretty complicated. Basically, you find the greatest denomination the total can divide into, use div to find out how many of those bills/coins are needed, then subtract that number times the bill value to get your remainder (you can't use mod here). Then repeat. Very long project.
gitoxa




PostPosted: Wed Sep 24, 2008 9:40 pm   Post subject: RE:outputing change in denominations

You can use modulus to tell you right away how much is left.

For example, says you have $8.32
Biggest money denomination would be a 5 dollar bill.

8.32 mod 5 = 3.32
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: