fork download
  1. Account={money=0, last_change=0}
  2. function Account:deposit(summ)
  3. self.money=self.money+summ
  4. self.last_change=summ
  5. end
  6. function Account:withdraw(summ)
  7. self.money=self.money-summ
  8. self.last_change=0-summ
  9. end
  10. function Account:status()
  11. print('Money: '..self.money)
  12. print('Last change: '..self.last_change)
  13. end
  14. function Account.new(money)
  15. return {money=money, last_change=0, withdraw=Account.withdraw, deposit=Account.deposit, status=Account.status}
  16. end
  17. acc=Account.new(0)
  18. function iter()
  19. print("Enter char(+ to deposit, - to withdraw, & to exit or ? to get status.). ")
  20. var=io.read()
  21. if var=='+' then
  22. print('Money: ')
  23. var=io.read()
  24. acc:deposit(var)
  25. return
  26. end
  27. if var=='-' then
  28. print('Money: ')
  29. var=io.read()
  30. acc:withdraw(var)
  31. return
  32. end
  33. if var=='&' then
  34. os.exit(0)
  35. end
  36. if var=='?' then
  37. acc:status()
  38. return
  39. end
  40. end
  41. for i=1, 5 do
  42. i=1
  43. iter()
  44. end
  45.  
Success #stdin #stdout 0.01s 2544KB
stdin
?
+
2300
?
-
1500
?
&
stdout
Enter char(+ to deposit, - to withdraw, & to exit or ? to get status.). 
Money: 0
Last change: 0
Enter char(+ to deposit, - to withdraw, & to exit or ? to get status.). 
Money: 
Enter char(+ to deposit, - to withdraw, & to exit or ? to get status.). 
Money: 2300
Last change: 2300
Enter char(+ to deposit, - to withdraw, & to exit or ? to get status.). 
Money: 
Enter char(+ to deposit, - to withdraw, & to exit or ? to get status.). 
Money: 800
Last change: -1500