Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void menu(double balance);
- double deposit(double balance);
- double makeBalance();
- double makeWithdraw(double balance);
- double deposit(double balance);
- int main () {
- double balance;
- menu(balance);
- }
- void menu(double balance) {
- cout << "Please make a choice, current balance: " << balance << endl;
- cout <<"1. Enter a starting balance" << endl;
- cout <<"2. Make a deposit" << endl;
- cout << "3. Make a withdrawal" << endl;
- cout <<"-1. Quit System" << endl;
- int input;
- cin >> input;
- if (input == 1) {
- balance = makeBalance();
- menu(balance);
- } else if (input == 2) {
- balance = deposit(balance);
- menu(balance);
- } else if (input == 3) {
- balance = makeWithdraw(balance);
- menu(balance);
- } else if (input != -1) {
- cout << "Invalid input, try again..." << endl;
- menu(balance);
- } if (input == -1) {
- cout << "System Quit End Balance: " << balance << endl;
- }
- }
- double makeBalance() {
- cout << "Please enter a starting balance: ";
- double userIn;
- cin >> userIn;
- cout <<"End balance: " << userIn << endl;
- return userIn;
- }
- double deposit(double balance) {
- cout << "Please enter an amount to deposit: ";
- double depositInput;
- cin >> depositInput;
- balance = balance + depositInput;
- cout << "End balance: " << balance << endl;
- return balance;
- }
- double makeWithdraw(double balance) {
- cout << "Please enter an amount to withdraw: ";
- double withdrawAmount;
- cin >> withdrawAmount;
- balance = balance - withdrawAmount;
- cout << "End balance: " << balance << endl;
- return balance;
- }
- // OUTPUT:
- Please make a choice, current balance: 0
- 1. Enter a starting balance
- 2. Make a deposit
- 3. Make a withdrawal
- -1. Quit System
- 4
- Invalid input, try again...
- Please make a choice, current balance: 0
- 1. Enter a starting balance
- 2. Make a deposit
- 3. Make a withdrawal
- -1. Quit System
- 1
- Please enter a starting balance: 1000
- End balance: 1000
- Please make a choice, current balance: 1000
- 1. Enter a starting balance
- 2. Make a deposit
- 3. Make a withdrawal
- -1. Quit System
- 2
- Please enter an amount to deposit: 500
- End balance: 1500
- Please make a choice, current balance: 1500
- 1. Enter a starting balance
- 2. Make a deposit
- 3. Make a withdrawal
- -1. Quit System
- 3
- Please enter an amount to withdraw: 750
- End balance: 750
- Please make a choice, current balance: 750
- 1. Enter a starting balance
- 2. Make a deposit
- 3. Make a withdrawal
- -1. Quit System
- -1
- System Quit End Balance: 750
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement