In: Computer Science
Assuming there are no deposits other than the original investment, the balance in a
savings account after one year may be calculated as
Amount = Principal *(1 + Rate/T)^T
Principal is the original investment in the savings account,
Rate is the annual interest rate, and T is the number of times the interest is
compounded during a year ( T is 4 if the interest iscompounded quarterly).
NOTE: the periodic rate r in the expression (1 + r) must match the duration of the period.
That is, a monthly period must use a monthly rate. When Rate is expressed as an Annual Percentage Rate (APR), then a monthy rate r is Rate/12.
Write a program that asks for the principal, the interest rate, and the number of times
the interest is compounded. It should display a formatted report similar to
Interest Rate: 4.25%
Times Compounded: 12
Principal: $ 1000.00
Interest: $ 43.34
Amount in Savings: $ 1043.34
Display your interactive dialog with the console
RUN THE FOLLOWING TEST CASES:
1) $ 5000 at 7.5% compounded 4 times.
2) $ 7500 at 5.2 % compounded 12 times.
3) $ 1000 at 10 % compounded(daily) 360 times.
Quality of craftsmanship is part of the grading.
C++ Program:
#include<iostream>
//For calculating power
#include<math.h>
//For rounding to 2 decimal places
#include<iomanip>
using namespace std;
int main(){
float principal,interest_rate,amount,interest;
int numberoftimes;
cout<<"Enter the principal:";
cin>>principal;
cout<<"Enter the interest rate:";
cin>>interest_rate;
cout<<"Enter the number of times interest is
compounded:";
cin>>numberoftimes;
//Interest rate is converted into decimal by dividing with
100
amount = principal *
pow((1+((interest_rate/100)/(numberoftimes))),numberoftimes);
interest = amount - principal;
cout<<fixed<<setprecision(2)<<"Interest Rate:
"<<interest_rate<<"%\n";
cout<<"Times Compounded:
"<<numberoftimes<<"\n";
cout<<fixed<<setprecision(2)<<"Principal: $
"<<principal<<"\n";
cout<<fixed<<setprecision(2)<<"Interest: $
"<<interest<<"\n";
cout<<fixed<<setprecision(2)<<"Amount in Savings:
$ "<<amount<<"\n";
return 0;
}
Output: