BobMe

wip money counter thing

Aug 30th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. var money = "$999" // coins are a bit bugged, don't crash your computer!
  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 seperatedeci(x) {
  43. x = x.toString()
  44. var numb = 0
  45. for (i = 0; i < x.length; i++) {
  46. if (x.substring(i,i+1) == ".") {
  47. numb = i
  48. }
  49. }
  50. return x.substring(numb,x.length)
  51. }
  52.  
  53. // calculate coins
  54. var num = seperatedeci(number)
  55. while (deterdeci(number) == true && num > 0) {
  56. if(num % .25 == 0 && quarter_on == true) {
  57. quarter++
  58. number = number -.25
  59. num = num - .25
  60. } else if(num % .10 == 0 && dime_on == true) {
  61. dime++
  62. number = number - .1
  63. num = num - .1
  64. } else if(num % .05 == 0 && nickel_on == true) {
  65. nickel++
  66. number = number - .05
  67. num = num - .05
  68. } else {
  69. penny++
  70. number = number - .01
  71. num = num - .01
  72. }
  73. }
  74.  
  75. // calculate notes
  76. while (number != 0) {
  77. if (number % 100 == 0 && hundred_on == true) {
  78. hundred++
  79. number = number - 100
  80. } else if(number % 50 == 0 && fifty_on == true) {
  81. fifty++
  82. number = number - 50
  83. } else if(number % 20 == 0 && twenty_on == true) {
  84. twenty++
  85. number = number - 20
  86. } else if(number % 10 == 0 && ten_on == true) {
  87. ten++
  88. number = number - 10
  89. } else if(number % 5 == 0 && five_on == true) {
  90. five++
  91. number = number - 5
  92. } else {
  93. one++
  94. number = number - 1
  95. }
  96. }
  97.  
  98. 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.")
  99. print("\n\n\nDEBUG: "+number)
Add Comment
Please, Sign In to add comment