Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var money = "$783.99" // coins are now fixed with reverse engineering
- //settings
- var hundred_on = true
- var fifty_on = true
- var twenty_on = true
- var ten_on = true
- var five_on = true
- var quarter_on = true
- var dime_on = true
- var nickel_on = true
- //variables
- var number = Number(money.substring(1))
- // >notes
- hundred = 0
- var fifty = 0
- var twenty = 0
- var ten = 0
- var five = 0
- var one = 0
- // >coins
- var quarter = 0
- var dime = 0
- var nickel = 0
- var penny = 0
- //end of variables
- // calculate coins
- function deterdeci(x) {
- x = Number(x)
- x = x.toString()
- var deter = false
- for (i = 0; i < x.length; i++) {
- if (x.substring(i,i+1) == ".") {
- deter = true
- }
- }
- return deter
- }
- function fixnumber(x) {
- var d = ""
- x = x.toString()
- for (i = 0; i < x.length; i++) {
- if (x.substring(i,i+1) == "." && x.substring(i+3,i+4) == "0") {
- d = x.substring(0,i+3)
- }
- }
- if (d != null) {
- return d
- }
- }
- function seperatedeci(x) {
- x = x.toString()
- var numb = 0
- for (i = 0; i < x.length; i++) {
- if (x.substring(i,i+1) == ".") {
- numb = i
- }
- }
- return x.substring(numb,x.length)
- }
- // coin fix
- if (deterdeci(number) == true) {
- var de = seperatedeci(number)
- de = de.toString()
- if (de.substring(2,3) == "8") {
- number = number -.01
- penny++
- } else if (de.substring(2,3) == "9") {
- number = number -.02
- penny = penny + 2
- var numbe = fixnumber(number)
- if (numbe != null && numbe != " " && numbe != "") {
- number = numbe
- }
- }
- }
- // calculate coins
- var num = seperatedeci(number)*100
- while (deterdeci(number) == true && num > 0) {
- if(num % 25 == 0 && quarter_on == true) {
- quarter++
- number = number -.25
- num = num - 25
- } else if(num % 10 == 0 && dime_on == true) {
- dime++
- number = number - .1
- num = num - 10
- } else if(num % 5 == 0 && nickel_on == true) {
- nickel++
- number = number - .05
- num = num - 5
- } else if(num % 1 == 0 && num >= 0) {
- penny++
- number = number - .01
- num = num - 1
- } else if (num <= 0) {
- break
- }
- }
- // calculate notes
- while (number != 0) {
- if (number % 100 == 0 && hundred_on == true) {
- hundred++
- number = number - 100
- } else if(number % 50 == 0 && fifty_on == true) {
- fifty++
- number = number - 50
- } else if(number % 20 == 0 && twenty_on == true) {
- twenty++
- number = number - 20
- } else if(number % 10 == 0 && ten_on == true) {
- ten++
- number = number - 10
- } else if(number % 5 == 0 && five_on == true) {
- five++
- number = number - 5
- } else {
- one++
- number = number - 1
- }
- }
- print("The Amount, "+money+", requires:\n\n"+hundred+" $100 notes;\n"+fifty+" $50 notes; \n"+twenty+" $20 notes; \n"+ten+" $10 notes; \n"+five+" $5 notes; \n"+one+" $1 notes; \n"+quarter+" quarters; \n"+dime+" dimes; \n"+nickel+" nickels; \nand "+penny+" pennies.")
- print("\n\n\nDEBUG: "+number)
Add Comment
Please, Sign In to add comment