In: Computer Science
Write a program to simulate a bank transaction. There are two bank accounts: checking and savings. First, ask for the initial balances of the bank accounts; reject negative balances. Then ask for the transactions; options are deposit, withdrawal, and transfer. Then ask for the account; options are checking and savings. Then ask for the amount; reject transactions that overdraw an account. At the end, print the balances of both accounts. in if and else statments only in c++
c++ code
#include <iostream>
using namespace std;
int main() {
        double checking_balance,saving_balance,amount;
        int transaction_option,account_type;
        cout<<"bank transaction window\n\n";
        cout<<"initial balance of the bank account(checking) :";
        cin>>checking_balance;
        if(checking_balance<0)  // when user enter -ve balance
        {
                cout<<"-ve balance not accepted";
                return main();
        }
        cout<<"initial balance of the bank account(saving) :";
        cin>>saving_balance;
                if(saving_balance<0) // when user enter -ve balance
        {
                cout<<"-ve balance not accepted";
                return main();
        }
        cout<<"\n\nenter transaction :\n1.deposit \n2.withdrawal\n3.transfer\noption:";
        cin>>transaction_option;
        if(transaction_option>3 or transaction_option<1)  // when user enter invalid number
        {
                cout<<"invalid transaction . enter 1 or 2 or 3\n";
                return main();
        }
        cout<<"\n\nenter account :\n1.checking \n2.savings\noption:";
        cin>>account_type;
        if(account_type>2 or account_type<1) // when user enter invalid number
        {
                cout<<"invalid account type enter 1 or 2\n";
                return main();
        }
                
        
        cout<<"\n\nenter amount :";
        cin>>amount;
        // deposit code = 1
        if(transaction_option==1)  
        {
                if(account_type==1)  // if account type is checking
                {
                checking_balance=checking_balance+amount;
                }
                if(account_type==2)  //if account type is saving
                {
                saving_balance=saving_balance+amount;
                }
                
        }
        //withdrawal code = 2
        if(transaction_option==2)
        {
                if(account_type==1 and (checking_balance-amount)>=0) // if account type is checking and not over drwing
                {
                checking_balance=checking_balance-amount;
            
                }
                        
                else if(account_type==2 and (checking_balance-amount)>=0) // if account type is saving and not over drwing
                {
                saving_balance=saving_balance-amount;
                }
                else // when over drawing
                {
                        cout<<"over draw , dont have enough balance\n";
                        return main();
                }
                
        }
        if(transaction_option==3)
        {
                if(account_type==1 and (saving_balance- amount)>=0) //transaction checking account to saving, and not over drwing
                {
                cout<<"\ntransaction from checking account to saving account\n";
                saving_balance=saving_balance+amount;
                checking_balance=checking_balance-amount;
                
                }
                
                else if(account_type==2 and (checking_balance - amount)>=0) // transaction from saving to checking and not over drwing
                {
                cout<<"\ntransaction from saving account to to checking account \n ";
                checking_balance=checking_balance+amount;
                saving_balance=saving_balance-amount;
                }
                else
                {
                        cout<<"over draw , dont have enough balance.\n";
                        return main();
                }
                
        }
        cout<<"checking account balance = "<<checking_balance<<endl; //printing balance
        cout<<"saving account balance   = "<<saving_balance;
        
   return 0;
}
output 1 -deposit

output 2 - withdrawal

output3 - transaction
