Question

Write a program to produce a table that shows the balance of a bank account after...

Write a program to produce a table that shows the balance of a bank account after each month, assuming that interest is compounded monthly and no additional money is added or withdrawn from the account.

Consider this example to understand how this calculation can be done with a loop. Suppose you put $10,000 into an account with an annual percentage rate (APR) of 5.0%. After one month, the account would receive an interest credit of 10000 * 5.0 / 1200. The annual percentage rate is divided by 1200, because we divide by 100 to convert a percentage to multiplier, and divide by 12 to convert an annual rate to a monthly rate. Therefore, the new account balance after one month would be

10000 + (10000 * 5.0 / 1200) = 10041.67

After the second month, the account would receive interest on its current balance, so the new balance would be

10041.67 + (10041.67 * 5.0 / 1200) = 10083.51

After the third month, the account would receive interest on its current balance, and the new balance would be

10083.51 + (10083.51 * 5.0 / 1200) = 10125.52

Requirements: Before the loop begins, your program should prompt the user to enter a starting balance (e.g., 10000), the annual percentage rate (e.g., 5.0), and the number of months to show in the table. The balance after each month should be shown with exactly two digits after the decimal point. A sample run of the program might appear as follows (input entered by the user is underlined, and the lines for months between 4 and 16 would be printed in place of …):

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question, Here is code in C++. Incase the program needs to rewritten in a different language or needs to be updated please do mention in the comments. Will update and share the code.

=============================================================

#include<iostream>
#include<iomanip>

using namespace std;


int main(){
  
   double balance;
   double rate;
   int months;
  
   cout<<"Enter the starting balance: $"; cin>>balance;
   cout<<"Enter the annual interest rate (as percentage): "; cin>>rate;
   cout<<"Enter the number of months: "; cin>>months;
  
  
   cout<<setw(10)<<left<<"Month"<<setw(18)<<right<<"Balance"<<endl;
   for(int month=1; month<=months; month++){
       balance = balance + balance*rate/1200;
       cout<<setw(10)<<left<<month
       <<setw(10)<<right<<"$ "
       <<setw(15)<<left<<setprecision(2)<<fixed<<balance<<endl;
   }
}

============================================================

import java.util.Scanner;

public class Balance {

    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);

        double balance;
        double rate;
        int months;


        System.out.print("Enter the starting balance: $");
        balance = scanner.nextDouble();
        System.out.print("Enter the annual interest rate (as percentage): ");
        rate = scanner.nextDouble();
        System.out.print("Enter the number of months: ");
        months = scanner.nextInt();

        System.out.printf("%-10s%18s\n", "Month", "Balance");

        for (int month = 1; month <= months; month++) {
            balance = balance + balance * rate / 1200;
            System.out.printf("%-10d%18s\n", month, "$ " + String.format("%.2f", balance));

        }
    }
}

Add a comment
Know the answer?
Add Answer to:
Write a program to produce a table that shows the balance of a bank account after...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ 18. Savings Account Balance Write a program that calculates the balance of a savings account...

    C++ 18. Savings Account Balance Write a program that calculates the balance of a savings account at the end of a three month period. It should ask the user for the starting balance and the annual interest rate. A loop should then iterate once for every month in the period, performing the following A) Ask the user for the total amount deposited into the account during that month. Do not accept negative numbers. This amount should be added to the...

  • i need this to be in OOP using C++ 25. Savings Account Balance Write a program...

    i need this to be in OOP using C++ 25. Savings Account Balance Write a program that calculates the balance of a savings account at the end of a three-month feried. It should ask the user for the starting balance and the annual interest rate. A loop abculd then iterate once for every month in the period, performing the following steps: B) A) Ask the user for the total amount deposited into the account during that month and add it...

  • 5.31 (Financial application: compute CD value) Suppose you put $10,000 into a CD with an annual...

    5.31 (Financial application: compute CD value) Suppose you put $10,000 into a CD with an annual percentage yield of 5.75%. After one month, the CD is worth 10000 + 10000 * 5.75 / 1200 = 10047.92 After two months, the CD is worth 10047.91 + 10047.91 * 5.75 / 1200 = 10096.06 After three months, the CD is worth 10096.06 + 10096.06 * 5.75 / 1200 = 10144.44 and so on. Write a program that prompts the user to enter...

  • JAVA PLEASE! Suppose you save $100 each month into a savings account with the annual interest...

    JAVA PLEASE! Suppose you save $100 each month into a savings account with the annual interest rate 5%. So, the monthly interest rate is 0.05/12 = 0.00417. After the first month, the value in the account becomes 100 * (1 + 0.00417) = 100.417 After the second month, the value in the account becomes (100 + 100.417) * (1 + 0.00417) = 201.252 After the third month, the value in the account becomes (100 + 201.252) * (1 + 0.00417)...

  • solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate...

    solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate and balance. The class constructor should accept the amount of the savings account's starting balance. The class should also have methods for subtracting the amount of a withdrawal, adding the amount of a deposit, and adding the amount of monthly twelve. To add the monthly interest rate to the balance,...

  • -----------Python program------------------- Instructions: For this assignment, you will write complete a program that allows a customer...

    -----------Python program------------------- Instructions: For this assignment, you will write complete a program that allows a customer to plan for retirement. Part 2: Generate a Retirement Planning Table: It's hard to decide how much you need to save for retirement. To help your customer visualize how long her nest egg will last, write a program that allows the user to generate a retirement planning table showing the number of months the savings will last for various combinations of starting account balance...

  • Hello I need C++ Code For the Following: Write a function declaration for a function that...

    Hello I need C++ Code For the Following: Write a function declaration for a function that computes interest on a credit card account balance. The function takes arguments for the initial balance, the monthly interest rate, and the number of months for which interest must be paid. The value returned is the interest due. Do not forget to compound the interest—that is, to charge interest on the interest due. The interest due is added into the balance due, and the...

  • This C++ Program should be written in visual studio 2017 You are to write a program...

    This C++ Program should be written in visual studio 2017 You are to write a program that can do two things: it will help users see how long it will take to achieve a certain investment goal given an annual investment amount and an annual rate of return; also, it will help them see how long it will take to pay off a loan given a principal amount, an annual payment amount and an annual interest rate. When the user...

  • Your program will ask the user to enter the amount of money they want to borrow,...

    Your program will ask the user to enter the amount of money they want to borrow, the interest rate, and the monthly payment amount. Your program will then determine how many months it will take to pay off that loan, what the final payment amount will be, and how much interest was paid over that time. If the monthly payment amount isn't high enough to pay off more than one month's interest, your program should notify the user what the...

  • Please I wish you use Python 3.7 for this problems. Q1. Write a program that receives...

    Please I wish you use Python 3.7 for this problems. Q1. Write a program that receives a series of numbers from the user and allows the user to press the enter key to indicate that he or she is finished providing inputs. After the user presses the enter key, the program should print the sum of the numbers and their average. Q2. The credit plan at TidBit Computer Store specifies a 10% down payment and an annual interest rate of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT