Sunday, January 23, 2022

messing with edge cases and loops

 #include <iostream>

using namespace std;
class base
{
protected:
    float total_balance;
    float withdwral_amount;
    float deposit_amount;
    void getbalance()
    {
        cout << "ENTER YOUR TOTAL BALANCE : " << endl;
        cin >> total_balance;
        if (total_balance < 0)
        {
            cout << "AMOUNT SHOULD BE ENTERED CORRECTLY" << endl;
        }
        else if (total_balance > 0)
        {
            total_balance = total_balance;
        }
        else
        {
            cout << "ENTER DIGITS" << endl;
        }

    }
    void depositAndWithdraw()
    {
        cout << "ENTER THE AMOUNT YOU WANT TO WITHDRAW : " << endl;
        cin >> withdwral_amount;
        if (withdwral_amount > total_balance)
        {
            cout << "YOU DONT HAVE ENOUGH MONEY IN YOUR ACCOUNT !" << endl;
        }
        else if (withdwral_amount <= total_balance && withdwral_amount >= 0)
        {
            total_balance = total_balance - withdwral_amount;
            cout << "ENTER THE AMOUNT YOU WANT TO DEPOSIT : " << endl;
            cin >> deposit_amount;
            if (deposit_amount > 0)
            {
                total_balance = total_balance + deposit_amount;
            }
            else if (deposit_amount < 0)
            {
                cout << "ENTER AMOUNT CORRECTLY" << endl;
                do
                {
                    cout << "ENTER THE AMOUNT YOU WANT TO DEPOSIT : " << endl;
                    cin >> deposit_amount;
                } while (deposit_amount < 0);
                if (deposit_amount > 0)
                {
                    total_balance = total_balance + deposit_amount;
                }
            }
            cout << "NOW BALANCE AFTER WITHDRAWL AND DEPOSIT IS: " << total_balance << endl;
        }
        else
        {
            cout << "ENTER AMOUNT CORRECTLY" << endl;
            do
            {
                cout << "ENTER THE AMOUNT YOU WANT TO WITHDRAW : " << endl;
                cin >> withdwral_amount;
            } while (withdwral_amount < 0);
            if (withdwral_amount <= total_balance && withdwral_amount >= 0)
            {
                total_balance = total_balance - withdwral_amount;
                cout << "ENTER THE AMOUNT YOU WANT TO DEPOSIT : " << endl;
                cin >> deposit_amount;
                if (deposit_amount > 0)
                {
                    total_balance = total_balance + deposit_amount;
                }
                else if (deposit_amount < 0)
                {
                    cout << "ENTER AMOUNT CORRECTLY" << endl;
                    do
                    {
                        cout << "ENTER THE AMOUNT YOU WANT TO DEPOSIT : " << endl;
                        cin >> deposit_amount;
                    } while (deposit_amount < 0);
                    if (deposit_amount > 0)
                    {
                        total_balance = total_balance + deposit_amount;
                    }
                }
                cout << "NOW BALANCE AFTER WITHDRAWL AND DEPOSIT IS: " << total_balance << endl;
            }
        }
    }
};
class finalAmountafter : public base
{
public:
    void displayfinalamount()
    {
        getbalance();

        if (total_balance > 0)
        {

            depositAndWithdraw();
        }

        if (total_balance < 0)
        {
            do
            {
                getbalance();
            } while (total_balance < 0);
            if (total_balance > 0)
            {

                depositAndWithdraw();
            }
        }
    }
};
int main()
{
    finalAmountafter obj;
    obj.displayfinalamount();
    return 0;
}

No comments:

Software scope

 In software engineering, the software scope refers to the boundaries and limitations of a software project. It defines what the software wi...

Popular Posts