57.7k views
3 votes
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 numbers.) This amount should be subtracted from the balance. C) Calculate the monthly interest. The monthly interest rate is the annual interest rate divided by twelve. Multiply the monthly interest rate by the balance, and add the result to the balance. After the last iteration, the program should display the ending balance, the total amount of deposits, the total amount of withdrawals, and the total interest earned.

User Ngtrkhoa
by
6.9k points

1 Answer

5 votes

Answer:

Check the explanation

Step-by-step explanation:

# include <iostream>

#include<iomanip>

using namespace std;

int main ()

{double start,balance,rate,deposit=0,withdraw=0,amt,sum,totInterest=0,interest;

int i;

cout<<setprecision(2)<<fixed;

cout<<"Enter starting balance: ";

cin>>balance;

start=balance;

cout<<"Enter annual interest rate: ";

cin>>rate;

rate/=12.;

for(i=1;i<=3;i++)

{cout<<"For month "<<i<<endl;

sum=balance;

cout<<"Enter total amount deposit: ";

cin>>amt;

while(amt<0)

{cout<<"Must not be negative-retry\\";

cout<<"Enter total amount deposit: ";

cin>>amt;

}

deposit+=amt;

balance+=amt;

cout<<"Enter total amount withdrawn: ";

cin>>amt;

while(amt<0||amt>balance)

{cout<<"Must not be negative, or greater than balance ($"<<balance<<")-retry\\";

cout<<"Enter total amount withdrawn: ";

cin>>amt;

}

withdraw+=amt;

balance-=amt;

interest=(sum+balance)/2.*rate;

totInterest+=interest;

balance+=interest;

}

cout<<"Starting balance at the beginning of the three month period: $"<<start<<endl;

cout<<"total deposits made during the three months: $"<<deposit<<endl;

cout<<"total withdrawals made during the three months: $"<<withdraw<<endl;

cout<<"total interest posted to the account during the three months $"<<totInterest<<endl;

cout<<"final balance: $"<<balance<<endl;

system("pause");

return 0;

}

Kindly check the output in the attached image below.

Write a program that calculates the balance of a savings account at the end of a period-example-1
User Kurroman
by
6.8k points