i wrote a program that calculates how many coins that a vending machine splits out and such, and it does work but i can't figure how it works. at the time, i was sure of the logic, but now i can't understand how this is possible.

change = (amountPaid - total);
double dollars = change/1.0;
double dollarReminder = change%1.0; 
//can't understand this part since the reminder would be 0

double quarters = dollarReminder/.25;
double quarterReminder = dollarReminder%.25;

ok the above code only calculates the dollar and quarter amount. to get the dollar amount, i divide the change by 1. For example, the change is $5.25/1 = 5.25, 5 would be the amount of single dollar bills to be given. however, there is no reminder, but there is??? and the dollar reminder is needed for the quarter calculation and so on. but there is no reminder for the dollar b/c anything divided by 1 is itself! how did this program even worked?

Edited by plasticfood: n/a

6 Years
Discussion Span
Last Post by masijade
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.