Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <cffunction name="splitbill" output="false" >
- <!--- Define the arguments --->
- <cfargument name="amount" required="yes" type="numeric">
- <cfargument name="people" required="yes" type="numeric">
- <!--- Set vars from the arguments, converting them to absolute values to handle
- negative numbers --->
- <cfset people = Abs(arguments.people)>
- <cfset amount = Abs(arguments.amount)>
- <!--- Convert the dollar amount to cents --->
- <cfset amount = amount * 100>
- <!--- Find the whole-cent amount for all but one person to pay --->
- <cfset spliteach = amount \ people>
- <!--- Find the aditional whole-cent amount for one person to pay --->
- <cfset splitextera = amount % people>
- <!--- Loop to add the base amount to each persons check --->
- <cfloop from="1" to="#people#" index="i">
- <cfset checkamount[#i#] = spliteach>
- </cfloop>
- <!--- Select who to add additional to --->
- <cfset additional = #RandRange(1, people, "SHA1PRNG")#>
- <!--- Add additional --->
- <cfset checkamount[#additional#] = checkamount[#additional#] + splitextera>
- <!--- Convert back to dollars --->
- <cfloop from="1" to="#arraylen(checkamount)#" index="i">
- <cfset checkamount[#i#] = checkamount[#i#] /100>
- </cfloop>
- <!--- Return value --->
- <cfreturn checkamount>
- </cffunction>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement