In: Computer Science
User asks you to develop a program that calculates and then prints interest earned on a bank balance. Program should print interest earned for the same balance when interest is accumulated annually, semiannually and quarterly. I need the C++ code!
C++ program Code for the given problem is provided below, please comment if any doubts:
#include <iostream>
using namespace std;
int main()
{
//declare the variables
float In, ra, Amt, yr;
//Read the amount
cout<<"Enter the amount balance: ";
cin>>Amt;
//Read annual interest rate
cout<<"Enter the annual interest rate: ";
cin>>ra;
//Read year number
cout<<"Enter the number of years: ";
cin>>yr;
//calculate and print interst earned for
//annual interst accumulation
In= Amt*(pow((1+(ra/100)), yr));
cout<<"Interest earned on annual accumulation
is: ";
cout<<In-Amt<<endl;
//calculate and print interst earned for
//semi-annual interst accumulation
In= Amt*(pow((1+(ra/(2*100))), (2*yr)));
cout<<"Interest earned on semi-annual
accumulation is: ";
cout<<In-Amt<<endl;
//calculate and print interst earned for
//quarterly interst accumulation
In= Amt*(pow((1+(ra/(4*100))), (4*yr)));
cout<<"Interest earned on quarterly accumulation
is: ";
cout<<In-Amt<<endl;
//
//system("pause");
return 0;
}
Sample Run: