So i made this bank account, i would like to display the total intrest and total balance i have been struggaling with it as i am a beginner to c++ If somebody could be able to help me simplify the code and add the totals would be great this is what i have done so far.

#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;

class bank_account
{
public:
    bank_account();
    bank_account(int account_no, float opening_balance);
    void deposit(float amount);
    void withdraw(float amount);
    float interest(float interest_rate);
    void balance();
    void display_balance();
    void display_interest_earned();
    void display_bank_heading();
    void display_bank_body();
    void display_bank_bottom();
    void display_total_balance();
    void display_total_interest();
private:
    int dm_account_no;
    float dm_balance;
    float dm_interest_rate;
    float dm_interest_earned;
    float dm_total_balance;
    float dm_total_interest;
};
class validation
{
public:
    bool test_userid(int user_id);
    bool test_userpin(int user_pin);

private:
    int dm_userid;
    int dm_userpin;
};

bank_account::bank_account()
{
    dm_account_no = 0;
    dm_balance =0.0;
}

bank_account::bank_account(int account_no, float opening_balance)
{
    dm_account_no = account_no;

    dm_balance = opening_balance*1.1;
}

void bank_account::deposit(float amount)
{
     dm_balance += amount;
}

void bank_account::withdraw(float amount)
{
    dm_balance -= amount;

}
void bank_account::display_total_balance()
{
    balance = ;
}

float bank_account::interest(float interest_rate)
{ dm_interest_rate = interest_rate;
    dm_interest_earned = dm_balance * dm_interest_rate;
    return dm_interest_earned;
}
void bank_account::display_interest_earned()

{   cout<<fixed<<setprecision(2)<<dm_interest_earned<<endl;}

void bank_account::display_balance()

{   cout<<fixed<<setprecision(2)<<dm_balance<<endl;}

void bank_account::display_bank_heading()
{
    cout<<" Bank Account System"<<endl;
    cout<<" ______________________________________"<<endl;
    cout<<"|                                      |"<<endl;
    cout<<"|"<<left << setw(13) <<"" << "Bank Report 1"  << right << setw(13) <<"|"<<endl;
    cout<<"|" <<left << setw(15) <<"" << "Closing"  << left << setw(8) <<""<<"Interest"<<"|" <<endl;
    cout<<"|" << left << setw(15) << "Account No" << "Balance" <<left<<setw(8) <<""<<"Earned"<<left<<setw(2)<<""<<"|" << endl;}

void bank_account::display_bank_body()
{   cout <<"|" << left << setw(15) << dm_account_no<< setw(15) << fixed << setprecision(2)
    << dm_balance <<setw(8)<<dm_interest_earned<<""<<"|"<<endl;}

void bank_account::display_bank_bottom()
{
    cout<<"|                                      |"<<endl;
    cout<<"|"<<"Total" <<right<<setw(10)<<balance<<"|"<<endl;
    cout<<"|______________________________________|"<<endl;
}

///float bank_account::balance()
///{dm_total_balance = 1905 ;
///dm_total_interest = 61.05;}

int reply;
int account_no[4]={80045001,80045002,80045003,80045004};
float opening_balance[4]={100,200,300,400};
int deposit[5]={100,200,300,400,10};
int withdraw[2]={50,155};
float interest_rate[4]={0.01,0.02,0.03,0.04};

bank_account account1,account2,account3,account4;
int main()
{

    class bank_account account1(account_no[0],opening_balance[0]);
    account1.display_bank_heading();
    account1.deposit(deposit[0]);
    account1.withdraw(withdraw[0]);
    account1.interest(interest_rate[0]);
    account1.display_bank_body();

    class bank_account account2(account_no[1],opening_balance[1]);
    account2.deposit(deposit[1]);
    account2.withdraw(withdraw[0]);
    account2.interest(interest_rate[1]);
    account2.display_bank_body();

    class bank_account account3(account_no[2],opening_balance[2]);
    account3.deposit(deposit[2]);
    account3.withdraw(withdraw[0]);
    account3.interest(interest_rate[2]);
    account3.display_bank_body();

    class bank_account account4(account_no[3],opening_balance[3]);
    account4.deposit(deposit[3]);
    account4.withdraw(withdraw[0]);
    account4.interest(interest_rate[0]);
    account4.display_bank_body();
    account4.display_bank_bottom();

    cout<< "Do you want to continue Yes or not"<<endl;
    cout<< "Enter Y to continue or N to exit"<<endl;
    cin>>reply;

    if (reply == 'N'){
        cout<<"Goodbye!"<<endl;
        exit(EXIT_FAILURE);}

    account1.display_bank_heading();
    account1.deposit(deposit[4]);
    account1.withdraw(withdraw[1]);
    account1.interest(interest_rate[0]);
    account1.display_bank_body();

    account2.deposit(deposit[1]);
    account2.withdraw(withdraw[0]);
    account2.interest(interest_rate[1]);
    account2.display_bank_body();

    account3.deposit(deposit[2]);
    account3.withdraw(withdraw[0]);
    account3.interest(interest_rate[2]);
    account3.display_bank_body();

    account4.deposit(deposit[3]);
    account4.withdraw(withdraw[1]);
    account4.interest(interest_rate[0]);
    account4.display_bank_body();
    account4.display_bank_bottom();

    cout<< "Enter 1 to continue or 2 to exit"<<endl;
    cin>>reply;
    if (reply == 2){
        cout<<"Goodbye!"<<endl;
        exit(EXIT_FAILURE);
    }
    cout<<"Continue processing"<<endl;
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.