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?

Where did you show the output? You probably casted to int there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.