Question

In: Computer Science

using C++ 23. Savings Account Balance Write a program that calculates the balance of a savings...

using C++

23. 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 steps:
A) Ask the user for the total amount deposited into the account during that month
and add it to the balance. Do not accept negative numbers.
B) Ask the user for the total amount withdrawn from the account during that
month and subtract it from the balance. Do not accept negative numbers or
numbers greater than the balance after the deposits for the month have been
added in.
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 month’s 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 report that includes the following
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

test case:

Test Case1:

Welcome to Your Bank!
What is your starting Balance? $100
What is the annual interest rate?. Please enter whole value. For example 6 for 6% :6

Month #1
Current Balance: $100.00
Please enter total amount of deposits: $2000
Please enter total amount of withdrawals: $200
New Balance: $1905.00

Month #2
Current Balance: $1905.00
Please enter total amount of deposits: $3000
Please enter total amount of withdrawals: $2000
New Balance: $2917.03

Month #3
Current Balance: $2917.03
Please enter total amount of deposits: $4000
Please enter total amount of withdrawals: $2000
New Balance: $4936.61

Start Balance:         $100.00
Total Deposits:        $9000.00
Total Withdrawals:     $4200.00
Total Interest Earned: $36.61
Final Balance:         $4936.61

Solutions

Expert Solution

// C++ program to calculate the balance of a savings account at the end of a three month period

#include <iostream>

#include <iomanip>

using namespace std;

int main() {

       double starting_balance, annual_interest, monthly_interest, ending_balance;

       double total_deposits= 0, total_withdrawals = 0, total_interest = 0;

       double deposit, withdrawal, interest, balance;

       cout<<fixed<<setprecision(2);

       cout<<"Welcome to Your Bank!"<<endl;

       // input of starting balance

       cout<<"What is your starting Balance? $";

       cin>>starting_balance;

       // input of annual rate of interest

       cout<<"What is the annual interest rate?. Please enter whole value. For example 6 for 6% : ";

       cin>>annual_interest;

       monthly_interest = annual_interest/1200; // get the monthly interest rate

       balance = starting_balance;

       ending_balance = balance;

       // loop to input the deposits and withdrawals for 3-month period

       for(int i=0;i<3;i++)

       {

             cout<<endl<<"Month#"<<(i+1)<<endl;

             cout<<"Current Balance: $"<<balance<<endl;

             // input of total deposit in the month

             cout<<"Please enter total amount of deposits: $";

             cin>>deposit;

             // validate the deposit to be non-negative, else re-prompt the user until valid

             while(deposit < 0)

             {

                    cout<<"Deposit amount cannot be negative"<<endl;

                    cout<<"Please enter total amount of deposits: $";

                    cin>>deposit;

             }

             /// add deposit to ending_balance and total_deposits

             total_deposits += deposit;

             ending_balance += deposit;

             // input of total withdrawal in the month

             cout<<"Please enter total amount of withdrawals: $";

             cin>>withdrawal;

             // validate withdrawal is not negative and not greater than available balance , if invalid re-prompt the user until user enters valid

             while(withdrawal < 0 || withdrawal > ending_balance)

             {

                    cout<<"Withdrawal amount cannot be negative or cannot be greater than available balance"<<endl;

                    cout<<"Please enter total amount of withdrawals: $";

                    cin>>withdrawal;

             }

             // add withdrawal to total withdrawals and subtract from ending_balance

             total_withdrawals += withdrawal;

             ending_balance -= withdrawal;

             // calculate interest

             interest = monthly_interest*((balance+ending_balance)/2);

             // add interest to ending_balance and total_interests

             ending_balance += interest;

             total_interest += interest;

             cout<<"New Balance: $"<<ending_balance<<endl;

             balance = ending_balance;

       }

       // output the report

       cout<<endl<<"Start Balance : $"<<starting_balance<<endl;

       cout<<"Total Deposits : $"<<total_deposits<<endl;

       cout<<"Total Withdrawals : $"<<total_withdrawals<<endl;

       cout<<"Total Interest Earned: $"<<total_interest<<endl;

       cout<<"Final Balance : $"<<ending_balance<<endl;

       return 0;

}

//end of program

Output:


Related Solutions

Write a program that calculates the balance of a savings account at the end of a...
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: 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...
Write a program that calculates the balance of a savings account at the end of a...
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: Ask the user for the amount deposited into the account during the month. (Do not accept negative numbers.) This amount should be added...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of test scores where the lowest score is dropped. It should use the following functions a) void getScores should have 4 double reference parameters (one for each test score) getScores should do the following: - read 4 test scores from the text file Lab11C.txt (Important: declare your ifstream infile and open the file inside this function, not in the main function) - store them in...
Create a Java Program to show a savings account balance. using eclipse IDE This can be...
Create a Java Program to show a savings account balance. using eclipse IDE This can be done in the main() method. Create an int variable named currentBalance and assign it the value of 0. Create an int variable named amountToSaveEachMonth. Prompt "Enter amount to save each month:" and assign the result to the int variable in step 2. Create an int variable name numberOfMonthsToSave. Prompt "Enter the number of months to save:" and store the input value into the variable...
Your task is to write a program in C or C++ that calculates the total amount...
Your task is to write a program in C or C++ that calculates the total amount of money a person has made over the last year. Your program will prompt the user for dollar amounts showing how much the user has made per job. Some users will have had more than one job, make sure your program allows for this. The program will print out the total made (all jobs) and will print out the federal and state taxes based...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $ 0.35 per mile. Your program should interact with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading: 13505.2 Enter ending odometer reading     : 13810.6 You traveled 305.40 miles. At $ 0.35 per mile, your reimbursement is $ 106.89. The values in red color are inputs for the program. The values in blue color are results of expressions.
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is worth 4 points, a B is worth 3 points, a C is worth 2 points, a D is worth 1 point, and an F is worth 0 points. For the purposes of this assignment, assume that all classes carry the same number of credit hours. 2) Use a sentinel-controlled loop to gather a variable number of letter grades. This should terminate the loop if...
Hotel Occupancy C++ Only Program Description Write a program that calculates the occupancy rate for a...
Hotel Occupancy C++ Only Program Description Write a program that calculates the occupancy rate for a hotel. The program should read its data from a file named "hotel.dat". The first line of this file will be a single integer specifying the number of floors in the hotel. Each of the remaining (N) lines will have two integers; the number of rooms on that floor and the number of occupied rooms on that floor. Your program should display the following: How...
In C++, Write a program that calculates pay for either an hourly paid worker or a...
In C++, Write a program that calculates pay for either an hourly paid worker or a salaried worker. Hourly paid workers are paid their hourly pay rate times the number of hours worked. Salaried workers are paid their regular salary plus any bonus they may have earned. The program should declare two structures for the following data: Hourly Paid: HoursWorked HourlyRate Salaried: Salary Bonus The program should also declare a union with two members. Each member should be a structure...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT