Guest User

Split The Bill

a guest
Nov 30th, 2012
116
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.    
  26.     <!--- Select who to add additional to --->
  27.     <cfset additional = #RandRange(1, people, "SHA1PRNG")#>
  28.    
  29.     <!--- Add additional --->
  30.     <cfset checkamount[#additional#] = checkamount[#additional#] + splitextera>
  31.    
  32.     <!--- Convert back to dollars --->
  33.     <cfloop from="1" to="#arraylen(checkamount)#" index="i">
  34.         <cfset checkamount[#i#] = checkamount[#i#] /100>
  35.     </cfloop>
  36.    
  37.     <!--- Return value --->
  38.     <cfreturn checkamount>
  39. </cffunction>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×