BobMe

finished money counter thing

Sep 13th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. var money = "$783.99" // coins are now fixed with reverse engineering
  2.  
  3. //settings
  4. var hundred_on = true
  5. var fifty_on = true
  6. var twenty_on = true
  7. var ten_on = true
  8. var five_on = true
  9. var quarter_on = true
  10. var dime_on = true
  11. var nickel_on = true
  12. //variables
  13. var number = Number(money.substring(1))
  14. // >notes
  15. hundred = 0
  16. var fifty = 0
  17. var twenty = 0
  18. var ten = 0
  19. var five = 0
  20. var one = 0
  21. // >coins
  22. var quarter = 0
  23. var dime = 0
  24. var nickel = 0
  25. var penny = 0
  26. //end of variables
  27.  
  28. // calculate coins
  29.  
  30. function deterdeci(x) {
  31. x = Number(x)
  32. x = x.toString()
  33. var deter = false
  34. for (i = 0; i < x.length; i++) {
  35. if (x.substring(i,i+1) == ".") {
  36. deter = true
  37. }
  38. }
  39. return deter
  40. }
  41.  
  42. function fixnumber(x) {
  43. var d = ""
  44. x = x.toString()
  45. for (i = 0; i < x.length; i++) {
  46. if (x.substring(i,i+1) == "." && x.substring(i+3,i+4) == "0") {
  47. d = x.substring(0,i+3)
  48. }
  49. }
  50. if (d != null) {
  51. return d
  52. }
  53. }
  54.  
  55. function seperatedeci(x) {
  56. x = x.toString()
  57. var numb = 0
  58. for (i = 0; i < x.length; i++) {
  59. if (x.substring(i,i+1) == ".") {
  60. numb = i
  61. }
  62. }
  63. return x.substring(numb,x.length)
  64. }
  65.  
  66. // coin fix
  67. if (deterdeci(number) == true) {
  68. var de = seperatedeci(number)
  69. de = de.toString()
  70. if (de.substring(2,3) == "8") {
  71. number = number -.01
  72. penny++
  73. } else if (de.substring(2,3) == "9") {
  74. number = number -.02
  75. penny = penny + 2
  76. var numbe = fixnumber(number)
  77. if (numbe != null && numbe != " " && numbe != "") {
  78. number = numbe
  79. }
  80. }
  81. }
  82. // calculate coins
  83. var num = seperatedeci(number)*100
  84. while (deterdeci(number) == true && num > 0) {
  85. if(num % 25 == 0 && quarter_on == true) {
  86. quarter++
  87. number = number -.25
  88. num = num - 25
  89. } else if(num % 10 == 0 && dime_on == true) {
  90. dime++
  91. number = number - .1
  92. num = num - 10
  93. } else if(num % 5 == 0 && nickel_on == true) {
  94. nickel++
  95. number = number - .05
  96. num = num - 5
  97. } else if(num % 1 == 0 && num >= 0) {
  98. penny++
  99. number = number - .01
  100. num = num - 1
  101. } else if (num <= 0) {
  102. break
  103. }
  104. }
  105.  
  106. // calculate notes
  107. while (number != 0) {
  108. if (number % 100 == 0 && hundred_on == true) {
  109. hundred++
  110. number = number - 100
  111. } else if(number % 50 == 0 && fifty_on == true) {
  112. fifty++
  113. number = number - 50
  114. } else if(number % 20 == 0 && twenty_on == true) {
  115. twenty++
  116. number = number - 20
  117. } else if(number % 10 == 0 && ten_on == true) {
  118. ten++
  119. number = number - 10
  120. } else if(number % 5 == 0 && five_on == true) {
  121. five++
  122. number = number - 5
  123. } else {
  124. one++
  125. number = number - 1
  126. }
  127. }
  128.  
  129. 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.")
  130. print("\n\n\nDEBUG: "+number)
Add Comment
Please, Sign In to add comment