Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void menu(double balance);
  5. double deposit(double balance);
  6. double makeBalance();
  7. double makeWithdraw(double balance);
  8. double deposit(double balance);
  9.  
  10. int main () {
  11. double balance;
  12. menu(balance);
  13. }
  14.  
  15. void menu(double balance) {
  16. cout << "Please make a choice, current balance: " << balance << endl;
  17. cout <<"1. Enter a starting balance" << endl;
  18. cout <<"2. Make a deposit" << endl;
  19. cout << "3. Make a withdrawal" << endl;
  20. cout <<"-1. Quit System" << endl;
  21. int input;
  22. cin >> input;
  23. if (input == 1) {
  24. balance = makeBalance();
  25. menu(balance);
  26. } else if (input == 2) {
  27. balance = deposit(balance);
  28. menu(balance);
  29. } else if (input == 3) {
  30. balance = makeWithdraw(balance);
  31. menu(balance);
  32. } else if (input != -1) {
  33. cout << "Invalid input, try again..." << endl;
  34. menu(balance);
  35. } if (input == -1) {
  36. cout << "System Quit End Balance: " << balance << endl;
  37. }
  38. }
  39.  
  40. double makeBalance() {
  41. cout << "Please enter a starting balance: ";
  42. double userIn;
  43. cin >> userIn;
  44. cout <<"End balance: " << userIn << endl;
  45. return userIn;
  46. }
  47.  
  48. double deposit(double balance) {
  49. cout << "Please enter an amount to deposit: ";
  50. double depositInput;
  51. cin >> depositInput;
  52. balance = balance + depositInput;
  53. cout << "End balance: " << balance << endl;
  54. return balance;
  55. }
  56.  
  57. double makeWithdraw(double balance) {
  58. cout << "Please enter an amount to withdraw: ";
  59. double withdrawAmount;
  60. cin >> withdrawAmount;
  61. balance = balance - withdrawAmount;
  62. cout << "End balance: " << balance << endl;
  63. return balance;
  64. }
  65.  
  66. // OUTPUT:
  67. Please make a choice, current balance: 0
  68. 1. Enter a starting balance
  69. 2. Make a deposit
  70. 3. Make a withdrawal
  71. -1. Quit System
  72. 4
  73. Invalid input, try again...
  74. Please make a choice, current balance: 0
  75. 1. Enter a starting balance
  76. 2. Make a deposit
  77. 3. Make a withdrawal
  78. -1. Quit System
  79. 1
  80. Please enter a starting balance: 1000
  81. End balance: 1000
  82. Please make a choice, current balance: 1000
  83. 1. Enter a starting balance
  84. 2. Make a deposit
  85. 3. Make a withdrawal
  86. -1. Quit System
  87. 2
  88. Please enter an amount to deposit: 500
  89. End balance: 1500
  90. Please make a choice, current balance: 1500
  91. 1. Enter a starting balance
  92. 2. Make a deposit
  93. 3. Make a withdrawal
  94. -1. Quit System
  95. 3
  96. Please enter an amount to withdraw: 750
  97. End balance: 750
  98. Please make a choice, current balance: 750
  99. 1. Enter a starting balance
  100. 2. Make a deposit
  101. 3. Make a withdrawal
  102. -1. Quit System
  103. -1
  104. System Quit End Balance: 750
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement