Advertisement
Guest User

correct

a guest
Nov 13th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5. void menu();
  6. bool withdraw(float&, const float);
  7. bool deposit(float&, const float);
  8. void checkBalance(float);
  9. int main()
  10. {
  11. bool leaveLoop = true;
  12. int choice;
  13. float balance = 0;
  14. float amount;
  15. char op;
  16. while (true)
  17. {
  18. menu();
  19. cin >> choice;
  20. switch (choice)
  21. {
  22. case(1):
  23. checkBalance(balance);
  24. break;
  25. case(2):
  26. char op;
  27. cout << " Would you like to deposit $10 by default or a custom amount, Type Y for Default or N for custom ? " << endl
  28. ;
  29. cin >> op;
  30. if (op == 'Y')
  31. {
  32. amount = 10;
  33. deposit(balance, amount);
  34. cout << showpoint << setprecision(2) <<
  35. fixed << "You have deposited $" << amount << endl;
  36. cout << "Your total balance is now: $"
  37. << balance << endl << endl;
  38. }
  39. else
  40. {
  41. cout << "Please enter the amount you would like to deposit : $";
  42. cin >> amount;
  43. cout << endl;
  44. deposit(balance, amount);
  45. cout << showpoint << setprecision(2) <<
  46. fixed << "You have deposited $" << amount << endl;
  47. cout << "Your total balance is now: $"
  48. << balance << endl << endl;
  49. }
  50. break;
  51. case(3):
  52. char op1;
  53. cout << " Would you like to withdraw $10 by default or a custom amount, Type Y for Default or N for custom ? " << endl
  54. ;
  55. cin >> op1;
  56. if (op1 == 'Y')
  57. {
  58. amount = 10;
  59. withdraw(balance, amount);
  60.  
  61.  
  62. }
  63. else
  64. {
  65. cout << "Please enter the amount you would like to withdraw : $";
  66. cin >> amount;
  67. cout << endl;
  68. withdraw(balance, amount);
  69.  
  70. }
  71. break;
  72. case(4):
  73. leaveLoop = false;
  74. cout << "Goodbye!";
  75. break;
  76. }
  77. if (leaveLoop == false)
  78. break;
  79. }
  80. return 0;
  81. }
  82. void checkBalance(float balance)
  83. {
  84. cout << std::fixed;
  85. cout << std::setprecision(2);
  86. cout << "Your current account balance is : " << balance << endl;
  87. }
  88. bool deposit(float& balance, const float amount = 10)
  89. {
  90. balance = balance + amount;
  91.  
  92. cout << std::fixed;
  93. cout << std::setprecision(2);
  94. cout << "Amount $" << amount << " successfully deposited into your account" << endl;
  95. return true;
  96. }
  97. bool withdraw(float& balance, const float amount = 10)
  98. {
  99. if (balance >= amount)
  100. {
  101.  
  102. balance = balance - amount;
  103.  
  104. cout << showpoint << setprecision(2) <<
  105. fixed << "You have withdrawn $" << amount << endl;
  106. cout << "Your total balance is now: $"
  107. << balance << endl << endl;
  108. }
  109. else
  110. {
  111. cout << "Insufficient Funds!" << endl;
  112. }
  113. return true;
  114. }
  115. void menu()
  116. {
  117. cout << "<-----Menu----->\n Please Select an option.\n 1. Check Balance\n 2. Deposit Funds\n 3. Withdraw Funds\n 4. Exit" << endl;
  118.  
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement