I have to do a simple program for school I was wondering if anyone can please to help me. I already created the program but it is not working properly and I have no idea how to fix it. Everything looks fine to me

Here's the assignment

Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number of months that have passed since the account was established. A loop should then iterate once for every month, performing the following:

A. Ask the user for the amount deposited into the account during the month (Do not accept negative numbers.) This amount should be added to the balance.

B. Ask the user for the amount withdrawn from the account during the month. (Do not accept negative number. Do not accept the amount if its is greater that the balance.) This amount should be subtracted from the balance.

C. Calculate the monthly interest and added to the balance.


#include <iostream>
	#include <iomanip>
	using namespace std;
	int main ()
	    double new_balance, ending_balance;
	    double interest_paid, annual_rate, principle_paid, payment;
	    cout << "Please enter the original loan amount $ (-1 to end the program):";
	    cin >> ending_balance;
	    cout << "Enter the interest rate on your loan %:";
	    cin >> annual_rate;
	    cout << endl;
	    // Setup a counter to count payments
	    int count = 1;
	    // Get the standard payment which is 1/20 of loan
	    payment = (ending_balance / 20.0);
	    while (ending_balance > 0.0) {
	        new_balance = ending_balance; 
	        // Calculate interest by multiplying rate against balance
	        interest_paid = new_balance * (annual_rate / 12.0);
	        // Subtract interest from payment
	        principle_paid = payment - interest_paid;
	        // Subtract final payment from running balance
	        ending_balance = new_balance - principle_paid;
			if ((new_balance + interest_paid) < payment) {
            cout << count << ". Payment: $" << (new_balance + interest_paid) << " Interest: $" << interest_paid << " Principle: $" << (new_balance - interest_paid) << " Loan Balance is: $0.00" << endl;
	        else {
            cout << count << ". Payment: $" << payment << " Interest: $" << interest_paid << " Principle: $" << principle_paid << " Loan Balance is: $" << ending_balance << endl;
	    return 0;


Edited 6 Years Ago by WaltP: Added CODE tags -- and STOP SHOUTING!

  1. Please begin to use the (CODE) button to post your code: Either press the button first, then paste between the (CODE) and (/CODE) tags, or paste first, highlight and then press the button. This results in properly indented, keyword-colored code with line numbers. All good things.
  2. It appears that you have started by trying to modify a 'loan balance' program. This is in fact a pretty good option: Change something similar to your need until it does the work. However, the impression I get is that you borrowed someone else's code, not your own, so 'HERE IS WHAT (I) HAVE DONE SO FAR' does not look appropriate. You can change that impression by saying how you came by the code. We all understand borrowing code, and re-using code.
  3. This is not the place to ask for someone to do all (or almost all) the work for you. You should post your code and ask a specific question (maybe two). Such as It does not compile using the XCode compiler on OS/X, with this error message "(whatever the message was)" or Whenever I try to call the withdraw() function (some problem description).
  4. After step 3, then ask for help.

Edited 4 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.