Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.7 kB
3
Indexable
#include <iostream>

using namespace std;

void showBalance(double balance);
double deposit();
double withdraw(double balance);

int main()
{
    double balance = 0;
    int choice = 0;

    do
    {

        cout << "Enter your Choice:\n";
        cout << "1. Show Balance\n";
        cout << "2. Deposit\n";
        cout << "3. Withdraw\n";
        cout << "4.Exit\n";
        cin >> choice;

        switch (choice)
        {

        case 1:
            showBalance(balance);

            break;

        case 2:
            balance = balance + deposit();
            showBalance(balance);
            break;

        case 3:
            balance = balance - withdraw(balance);
            showBalance(balance);
            break;

        case 4:
            cout << "Thanks for visiting";
            break;

        default:
            cout << "Invalid";
        }

    } while (choice != 4);
    return 0;
}

void showBalance(double balance)
{
    cout << "Your Balance is Rs. " << balance << ".\n\n";
}

double deposit()
{
    double amt = 0;
    cout << "Enter deposit amount= Rs. ";
    cin >> amt;
    if (amt > 0)
    {
        return amt;
    }

    else
    {
        cout << "That invalid\n";
    }
}

double withdraw(double balance)
{
    double amt;
    cout << "Enter withdraw amount= Rs. ";
    cin >> amt;

    if (balance < amt)
    {
        cout << "Insufficient balance";
        return 0;
    }
    else if (amt < 0)
    {
        cout << "Invalid amount";
        return 0;
    }
    else
    {
        cout<<"You have withdrawn "<<amt<<".\n";
        return amt;
    }
}