# Friday Puzzler: Split the Bill

a guest
Nov 30th, 2012
84
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. <cffunction name="splitbill" output="false" >
2.
3.     <!--- Define the arguments  --->
4.     <cfargument name="amount" required="yes" type="numeric">
5.     <cfargument name="people" required="yes" type="numeric">
6.
7.     <!--- Set vars from the arguments, converting them to absolute values to handle
8.           negative numbers --->
9.     <cfset people = Abs(arguments.people)>
10.     <cfset amount = Abs(arguments.amount)>
11.
12.     <!--- Convert the dollar amount to cents --->
13.     <cfset amount = amount * 100>
14.
15.     <!--- Find the whole-cent amount for all but one person to pay --->
16.     <cfset spliteach = amount \ people>
17.
18.     <!--- Find the aditional whole-cent amount for one person to pay --->
19.     <cfset splitextera = amount % people>
20.
21.     <!--- Loop to add the base amount to each persons check --->
22.     <cfloop from="1" to="#people#" index="i">
23.         <cfset checkamount[#i#] = spliteach>
24.     </cfloop>
25.
27.     <cfset additional = #RandRange(1, people, "SHA1PRNG")#>
28.
31.
32.     <!--- Return value --->
33.     <cfreturn checkamount>
34. </cffunction>
RAW Paste Data