Question

In: Computer Science

Write a program to simulate a bank transaction. There are two bank accounts: checking and savings....

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++

Solutions

Expert Solution

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


Related Solutions

assigsment-Write a program to simulate a bank transaction. There are two bank accounts: checking and savings....
assigsment-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 c++ work done- output and need help with the...
There are two kinds of bank accounts: checking and savings. You can deposit to (i.e. add...
There are two kinds of bank accounts: checking and savings. You can deposit to (i.e. add money in) or withdraw (i.e. take money out) from an account. A checking account can be withdrawn with an unlimited number of times. A savings account can only be withdrawn at most N times per calendar month. Checking accounts have no monthly fee. Savings accounts have a fixed monthly fee X. But if you deposit at least a money amount of M each month,...
Write a Java program to simulate the rolling of two dice. The application should use an...
Write a Java program to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12. Your application should roll the dice 36,000,000 times. Store the results of each roll...
In Java, Write a Java program to simulate an ecosystem containing two types of creatures, bears...
In Java, Write a Java program to simulate an ecosystem containing two types of creatures, bears and fish. The ecosystem consists of a river, which is modeled as a relatively large array. Each cell of the array should contain an Animal object, which can be a Bear object, a Fish object, or null. In each time step, based on a random process, each animal either attempts to move into an adjacent array cell or stay where it is. If two...
Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market,...
Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market, to attract customers as well as meet their specific needs. Two of the most commonly used accounts are savings and checking. Each of these accounts has various options. For example, you may have a savings account that requires no minimum balance but has a lower interest rate. Similarly, you may have a checking account that limits the number of checks you may write. Another...
Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market,...
Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market, to attract customers as well as meet their specific needs. Two of the most commonly used accounts are savings and checking. Each of these accounts has various options. For example, you may have a savings account that requires no minimum balance but has a lower interest rate. Similarly, you may have a checking account that limits the number of checks you may write. Another...
Problem Statement: Banks offer various types of accounts, such as savings, checking, certificate of deposits, and...
Problem Statement: Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market, to attract customers as well as meet with their specific needs. Two of the most commonly used accounts are savings and checking. Each of these accounts has various options. For example, you may have a savings account that requires no minimum balance but has a lower interest rate. Similarly, you may have a checking account that limits the number of checks you...
Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market,...
Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market, to attract customers as well as meet with their specific needs. Two of the most commonly used accounts are savings and checking. Each of these accounts has various options. For example, you may have a savings account that requires no minimum balance but has a lower interest rate. Similarly, you may have a checking account that limits the number of checks you may write....
Discuss checking and savings accounts. How do they work? How are they similar? How do they...
Discuss checking and savings accounts. How do they work? How are they similar? How do they differ? What are CDs? What are advantages of an ATM?
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT