Results 1 to 1 of 1
- 01-25-2012, 07:54 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 40
- Rep Power
- 0
Vending Machine Change - LOGIC Understanding ISSUE
NEWBIE JAVA:
I have a simple java program to write which tells the user combination of coins that equals to the amount of change i.e:
user input 87
output:
3 quarters
1 dime
0 nickels
2 pennies
SIMPLE RIGHT?! - we'll my book shows the example BUT my confusion is how the program remembers the remainder which is passed to the next column of let say dime
i.e
originalAmount = amount;
quarters = amount /25;
amount = amount % 25; <---- this is confusing for me?!?! how can the integer = integer % 25
dimes = amount / 10; <--- HOW THE PROGRAM remembers the "remainder" instead of the original user input as the code it self tells you dimes = amount where "amount" is what user input NOT remainder. PLease help.
amount = amount % 10;
so on ....;

What I don't understand is HOW this algorithm works. I mean we have
int amount where user inputs the number we get the first calculation
amount/25 = how many quarters and then amount %25 WILL tell us about
the reminder. By looking at this piece of code I would say that the
system should start the calculation for the dimes again from the
original number since the code says dimes = amount/10 AND amount =
amount%10. My understanding is that the calculation should be done
from the original user input.
Book or code it self is not clear for me how the reminder is
"REMEMBERED" and then pass on to the next calculation>!?!?
UNLESS the code: amount=amount%25 gets the remainder so the next code under it is REQUIRED to read from the last prompt code - Please advise if I think right?
Please advise,
dk
Similar Threads
-
vending machine
By Timmy1596 in forum JCreatorReplies: 2Last Post: 09-16-2011, 09:45 PM -
Understanding EJB "machine" ;-)
By cygan in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 09-08-2011, 09:24 PM -
Recursive Change Machine
By EZlats in forum New To JavaReplies: 2Last Post: 04-01-2011, 03:46 AM -
logic for Uploading all the local files from local machine to remote server using FTP
By agangaia in forum New To JavaReplies: 1Last Post: 03-05-2011, 05:47 PM -
Understand my logic errors and better understanding method and class creation
By freethinker89 in forum New To JavaReplies: 3Last Post: 10-06-2008, 11:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks