# Split the bill

a guest
Nov 30th, 2012
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. <cfscript>
2. param name='numOfPeople' default='5';
3. param name='bill' default='143.03';
4. param name='tip' default='0.15';
5.
6. function SplitBill(p,b,t){ // p = number of people, b = bill total, t = percentage of tip to be left default to 15%
7. var rt = arrayNew(1);
8. var tb = 0;
9. var eachBase = 0;
10. var remainder = 0;
11. var ranPerson = 0;
12. if (!isNumeric(arguments.p)||!isNumeric(arguments.b)){
13. return 'Enter Bill and number of people as numbers';}
14. if (!isNumeric(arguments.t)){arguments.t = 0.15;}
15. var tb = arguments.b*(1+arguments.t);
16. var eachBase = int(tb*100/arguments.p);
17. var remainder = arguments.b*100 mod arguments.p;
18. var ranPerson = randRange(1,arguments.p);
19. for(i=1;i<=arguments.p;i++){
20. rt[i]=eachBase;
21. }
22. while(remainder>0){
23. rt[ranPerson]=rt[ranPerson]+1;
24. ranPerson = ranPerson+1;
25. if(ranPerson > arrayLen(rt)){ranPerson=1;}
26. remainder = remainder-1;
27. }
28. for(i=1;i<=arguments.p;i++){
29. rt[i]=dollarFormat(rt[i]/100);
30. }
31. return rt;
32. }
33. result = SplitBill(numOfPeople,bill,tip);
34. writeDump(result);
35. </cfscript>
RAW Paste Data