You are on page 1of 1

function[ e2, e1, c50, c20, c10, c5, c2, c1,] = change(amountDue, amountPaid)

e2 = 0;
e1 = 0;
c50 = 0;
c20 = 0;
c10 = 0;
c5 = 0;
c2 = 0;
c1 = 0;

change = amountPaid - amountDue;


roundchange = floor(change);
e2 = floor(roundchange/200);
rest1 = roundchange-(e2*200);
e1 = floor(rest1/100);
rest2 = rest1 - (e1*100);
c50 = floor(rest2/50);
rest3 = rest2 - (c50*50);
c20 = floor(rest3/20);
rest4 = rest3 - (c20*20);
c10 = floor(rest4/10);
rest5 = rest4 - (c10*10);
c5 = floor(rest5/5);
rest6 = rest5 - (c5*5);
c2 = floor(rest6/2);
rest7 = rest6 - (c2*2);
c1 = floor(rest7/1);

end

You might also like