I am trying to print out a report for a 12 month interest summary. So far, I cannot seem to get the ending balance for the previous month to be the starting balance for the next month. Here is the code I have so far:

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

#include "SavingsAccount.h"

int main()
{
    //Create one instance of a SavingsAccount
    SavingsAccount myAccount("Z1234A", 4000.0, 0.004);
    double currentBalance;
    char makeDeposit = ' ';
    double amount = 0.0;
    char makeWithdrawal = ' ';
    double INT_RATE = .004;
    double startingBal = 0.0;
    double endingBal = 0.0;

    //Set decimal spaces to 2
    cout << fixed << setprecision(2);

    string accountNumber;
    accountNumber = myAccount.getAcctNo();

    //Display the name of software and company
    cout << setw(55) << " BANKING SOLUTIONS SOFTWARE 1.0 " << endl;
    cout << setw(54) << "Prioleau Banking Corporation " << endl << endl;

    //Welcome the customer
    cout << setw(61) << "Welcome to the Prioleau Banking Corporation!" << endl << endl;

    //Display the current state of the account including
    //account number, current balance and interest rate 
    accountNumber = myAccount.getAcctNo();
    cout << "Your account number is: " << accountNumber << endl;

    currentBalance = myAccount.getBalance();
    cout << "Your current balance is: $" << currentBalance << endl;

    double startingRate;
    startingRate = myAccount.getInterestRate();
    cout << "The current interest rate is: " << ".4%" << endl << endl;

    //Customer makes a deposit
    cout << "Will you be making a deposit today (Y or N)?" << endl;
    cin >> makeDeposit;
    cout << endl;

    if (toupper(makeDeposit) == 'Y')
    {
        cout << "Please enter the amount that you would like to deposit." << endl;
        cin >> amount;
        cout << endl;

        myAccount.addToBalance(amount);
        currentBalance = myAccount.getBalance();

        //Display the ending state of the account
        cout << "Your current balance is now: $" << currentBalance << endl << endl;
    }
    else
        cout << "Thank you." << endl << endl;

    //Customer makes a withdrawal
    cout << "Will you be making a withdrawal today (Y or N)?" << endl;
    cin >> makeWithdrawal;
    cout << endl;

    if (toupper(makeWithdrawal) == 'Y')
    {
        cout << "Please enter the amount that you would like to withdraw." << endl;
        cin >> amount;
        cout << endl;

        myAccount.withdrawFromBalance(amount);
        currentBalance = myAccount.getBalance();

        //Display the ending state of the account
        cout << "Your current balance is now: $" << currentBalance << endl << endl;
    }
    else
        cout << "Thank you." << endl << endl;

    //Display a 12-month summary of the account that shows the effect
    //of the current interest rate on the growth of the balance
    //assuming that the interest is applied as simple interest once per month
    cout << "As of today's balance, here is a 12-month summary of the account that "<<
            "shows the effect of the current interest rate on the growth " << 
            "of the balance; assuming that the interest is applied as simple interest "<<
            "once per month." << endl << endl << endl;

    //Headers
    cout << "Month" << setw(20) << "Starting" << setw(20) << "Interest" << setw(20)
             << "Ending" << endl;
    cout << "  #" << setw(21) << "Balance" << setw(19) << "Earned" << setw(23)
             << "Balance" << endl;

    //line number variable for print out
    int lineNum = 1;

    //Formula for ending balance
    endingBal = currentBalance + (currentBalance * INT_RATE);

    //12 month interest report output line 1        
    cout << setw(3) << lineNum << setw(21) << currentBalance + INT_RATE << setw(18) << currentBalance * INT_RATE 
        << setw(24) << endingBal;
        cout << endl;

    //Formula for starting balance
    startingBal = endingBal;    

    while (lineNum <= 11)
    {
        //Line number counter for 12 month interest report output
        lineNum += 1;

        //12 month of interest report output
        cout << setw(3) << lineNum << setw(21) << endingBal + INT_RATE << setw(18) << startingBal * INT_RATE 
            << setw(24) << endingBal;
            cout << endl;

    }
    //end while

    cout << endl << endl;
    cout << "Thank you for choosing Prioleau Banking Corporation. Have a wonderful day!" << endl;

    cout << endl << endl;
    system ("pause");
    return 0;
}

Recommended Answers

All 3 Replies

Congratulations! You're no longer a DaniWeb newbie.<br /> <br />
Your DaniWeb account has just been upgraded from newbie status and now you have the ability to take advantage of everything the community has to offer.<br /> <br />
You can now enjoy an advertisement-free DaniWeb by ticking the checkbox to Disable Ads in your profile. You will no longer have to fill out the human verification check when you post. You can also now send unlimited private messages, contribute new code snippets, and tag articles with never-before-used tags.

Here is the class associated with this program:

class SavingsAccount
{
    //Data declarations
private:
    string accountNumber;
    double balance;
    double rate;

    //Methods declarations
public:
    SavingsAccount(string, double, double); //Prototype for constructor
    double getBalance();
    void addToBalance(double);
    string getAcctNo();
    double getInterestRate();
    void withdrawFromBalance(double);
};

//Methods implementation

//This is the constructor
SavingsAccount::SavingsAccount(string acctNo, double startingBalance, double startingRate)
{
    accountNumber = acctNo;
    balance = startingBalance;
    rate = startingRate;
}

double SavingsAccount::getBalance()
{
    return balance;
}

void SavingsAccount::addToBalance(double amount)
{
    balance += amount;
}

string SavingsAccount::getAcctNo()
{
    return accountNumber;
}

double SavingsAccount::getInterestRate()
{
    return rate;
}

void SavingsAccount::withdrawFromBalance(double amount)
{
    balance -= amount;
}
//END OF CLASS SavingsAccount

You've made it far harder than it needs to be.

Essentially, you need to change the value of current balance 12 times. Something like this:

current_balance = current_balance+(current_balance * INT_RATE);

If you remove starting_balance and ending_balance completely you'll be making it a lot simpler to keep track of.

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.