Question
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 balance. Ask the user for the total amount withdrawn from the account during that month. Do not accept negative numbers or numbers greater than the balance after the deposits for the month have been added in. B) C) Calculate the interest for that month. The monthly interest rate is the annual interest rate divided by 12. Multiply the monthly interest rate by the average of that months starting and ending balance to get the interest amount for the month. This amount should be added to the balance. After the last iteration, the program should display a final report that includes the follow ing information: . starting balance at the beginning of the three-month period. . total deposits made during the three months total withdrawals made during the three months . total interest posted to the account during the three months . final balance.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int main() {

    double startingBalance, interestRate;
    double monthStartBalance, monthEndBalance;
    double balance;
    double total_deposits = 0, total_withdrawls = 0, total_interest = 0;

    cout << "Enter starting balance : ";
    cin >> startingBalance;
    while(startingBalance < 0) {
        cout << "Invalid.\nEnter starting balance : ";
        cin >> startingBalance;
    }

    cout << "Enter annual interest rate : ";
    cin >> interestRate;
    while(interestRate < 0) {
        cout << "Invalid.\nEnter annual interest rate : ";
        cin >> interestRate;
    }

    balance = startingBalance;

    for(int month=1; month<=3; month++) {

        monthStartBalance = balance;

        double amount_deposited, amount_withdrawn;
        cout << "Enter amount deposited in month " << month << ": ";
        cin >> amount_deposited;
        while(amount_deposited < 0) {
            cout << "Invalid.\nEnter amount deposited in month " << month << ": ";
            cin >> amount_deposited;
        }

        total_deposits += amount_deposited;
        balance += amount_deposited;

        cout << "Enter amount withdrawn in month " << month << ": ";
        cin >> amount_withdrawn;
        while(amount_withdrawn > balance || amount_withdrawn < 0) {
            cout << "Invalid.\nEnter amount withdrawn in month " << month << ": ";
            cin >> amount_withdrawn;
        }

        total_withdrawls += amount_withdrawn;
        balance -= amount_withdrawn;

        monthEndBalance = monthStartBalance + amount_deposited - amount_withdrawn;

        double avg = (monthStartBalance + monthEndBalance)/2.0;
        double interest = avg * interestRate / 1200;

        total_interest += interest;

        balance += interest;
    }

    cout << "\n\nStarting balance: $" << startingBalance << endl;
    cout << "Total depositis: $" << total_deposits << endl;
    cout << "Total withdrawls: $" << total_withdrawls << endl;
    cout << "Total interest posted: $" << total_interest << endl;
    cout << "Final Balance: $" << balance << endl;

}

saved gcc version 4.6.3 monthstartBalancebalance; 30 31 32 double amount deposited, amount withdraun; cout << Enter amount deposited in month << month << cin >>amount_deposited; while(amount_deposited < 0) Enter starting balance 1806 Enter annual interest rate: Enter amount deposited in month 1: 200e Enter amount withdrawn in month 1: 6000 Enter amount deposited in month 2: 3000 Enter amount withdrawn in month 2: 10臼 Enter amount deposited in month 3: 1000 Enter amount withdrawn in month 3 1500 3-4 35 36 3/ cout <<Invalid.\nEnter amount deposited in month << month << : ; cin amount deposited; Starting balance: $4000 Total depositis: $6800 Total withdrawls: $856e Total interest posted: $31.8895 Final Balance: $1531.89 total depositsamount deposited; balance amount deposited; 42 cout く< Enter amount withdrawn in month “ << month << “, ; cin >>amount_withdrawn; while(amount_withdrawn balance amount withdrawn <0) [ 43 45 cout <<Invalid.nEnter amount withdrawn in month << month <<:; cin amount withdrawn; 48 19 50 51 52 total withdrawls amount withdrawn; balancc -amount_withdrawn; monthE ndBalance monthstartBalance amount_deposited amount_withdrawn; double avg (monthstartBalance + monthEndBalance)/2-0; 56 57 58 double interest - avg intere stRate / 1200; total interest interest; balance interest; 60

Hi. Please find the answer above.. In case of any doubts, you may ask in comments. You may upvote the answer if you feel i did a good work!

Add a comment
Know the answer?
Add Answer to:
C++ 18. Savings Account Balance Write a program that calculates the balance of a savings account...
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
  • 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...

  • 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,...

  • Write in C++ using emacs. Write a program that calculates the ending balance of several savings...

    Write in C++ using emacs. Write a program that calculates the ending balance of several savings accounts. The program reads information about different customers’ accounts from an input file, “accounts.txt”. Each row in the file contains account information for one customer. This includes: the account number, account type (premium, choice, or basic account), starting balance, total amount deposited, and total amount withdrawn. Your program should: - open the file and check for successful open, - then calculate the ending balance...

  • Write a program that uses nested loops to collect data and calculate the average rainfall over...

    Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should prompt the user for the number of years. Be sure to ask for each months average rainfall for each year. The outer loop will iterate once for each year while the inner loop will iterate 12 times(one time per month) prompting for the months average rainfall on each iteration. Display the number of months, the total inches...

  • 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....

  • 5. Create a java application that uses nested loops to collect data and calculate the average...

    5. Create a java application that uses nested loops to collect data and calculate the average rainfall over a peniod of years First the program should ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month, the program should display the number of months, the total...

  • Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending...

    Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending monthly balances for a checking account and a savings account. --->Console Welcome to the Account application Starting Balances Checking: $1,000.00 Savings:  $1,000.00 Enter the transactions for the month Withdrawal or deposit? (w/d): w Checking or savings? (c/s): c Amount?: 500 Continue? (y/n): y Withdrawal or deposit? (w/d): d Checking or savings? (c/s): s Amount?: 200 Continue? (y/n): n Monthly Payments and Fees Checking fee:              $1.00 Savings...

  • Suppose you have a certain amount of money in a savings account that earns compound monthly...

    Suppose you have a certain amount of money in a savings account that earns compound monthly interest, and you want to calculate the amount that you will have after a specific number of months. The formula is as follows: f = p * (1 + i)^t • f is the future value of the account after the specified time period. • p is the present value of the account. • i is the monthly interest rate. • t is the...

  • Write them in python IDLE ***** 5. Average Rainfall Write a program that uses nested loops...

    Write them in python IDLE ***** 5. Average Rainfall Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations,...

  • Write a program that calculates the amount of money that you must invest In a savings...

    Write a program that calculates the amount of money that you must invest In a savings account at a given interest rate for a given number of years to have a certain dollar amount at me end of the period Y our program will ask the user for the amount the user wants to have at the end of the term (future value). the number of years the user plans to let the money stay in the account, and the...

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