Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- void menu();
- bool withdraw(float&, const float);
- bool deposit(float&, const float);
- void checkBalance(float);
- int main()
- {
- bool leaveLoop = true;
- int choice;
- float balance = 0;
- float amount;
- char op;
- while (true)
- {
- menu();
- cin >> choice;
- switch (choice)
- {
- case(1):
- checkBalance(balance);
- break;
- case(2):
- char op;
- cout << " Would you like to deposit $10 by default or a custom amount, Type Y for Default or N for custom ? " << endl
- ;
- cin >> op;
- if (op == 'Y')
- {
- amount = 10;
- deposit(balance, amount);
- cout << showpoint << setprecision(2) <<
- fixed << "You have deposited $" << amount << endl;
- cout << "Your total balance is now: $"
- << balance << endl << endl;
- }
- else
- {
- cout << "Please enter the amount you would like to deposit : $";
- cin >> amount;
- cout << endl;
- deposit(balance, amount);
- cout << showpoint << setprecision(2) <<
- fixed << "You have deposited $" << amount << endl;
- cout << "Your total balance is now: $"
- << balance << endl << endl;
- }
- break;
- case(3):
- char op1;
- cout << " Would you like to withdraw $10 by default or a custom amount, Type Y for Default or N for custom ? " << endl
- ;
- cin >> op1;
- if (op1 == 'Y')
- {
- amount = 10;
- withdraw(balance, amount);
- }
- else
- {
- cout << "Please enter the amount you would like to withdraw : $";
- cin >> amount;
- cout << endl;
- withdraw(balance, amount);
- }
- break;
- case(4):
- leaveLoop = false;
- cout << "Goodbye!";
- break;
- }
- if (leaveLoop == false)
- break;
- }
- return 0;
- }
- void checkBalance(float balance)
- {
- cout << std::fixed;
- cout << std::setprecision(2);
- cout << "Your current account balance is : " << balance << endl;
- }
- bool deposit(float& balance, const float amount = 10)
- {
- balance = balance + amount;
- cout << std::fixed;
- cout << std::setprecision(2);
- cout << "Amount $" << amount << " successfully deposited into your account" << endl;
- return true;
- }
- bool withdraw(float& balance, const float amount = 10)
- {
- if (balance >= amount)
- {
- balance = balance - amount;
- cout << showpoint << setprecision(2) <<
- fixed << "You have withdrawn $" << amount << endl;
- cout << "Your total balance is now: $"
- << balance << endl << endl;
- }
- else
- {
- cout << "Insufficient Funds!" << endl;
- }
- return true;
- }
- void menu()
- {
- cout << "<-----Menu----->\n Please Select an option.\n 1. Check Balance\n 2. Deposit Funds\n 3. Withdraw Funds\n 4. Exit" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement