Write a C++ program to compute simple interest and compound interest.
In this section, you will learn how to read the principle, rate and time from the user and write a C++ program to calculate simple interest and the total amount.
SIMPLE INTERSET = (P*R*T)/100
(Here, P = Principal Amount, R= Rate and T= Time)
TOTAL AMOUNT = P + Simple Interest
Logic :
- Take input principle amount, time and rate in some variable.
- Then take input time in some variable.
- Then take input rate in some variable.
- Find simple interest using formula mentioned above.
- Finally, print the value of Simple Interest.
- Then, to find the Total amount add principal amount to the simple interest.
COMPOUND INTEREST :-
TOTAL AMOUNT = P*(1 + R/100)T
COMPOUND INTEREST = TOTAL AMOUNT – P
C++ program to compute simple interest and compound interest.
// Program to compute simple interest and compound interest. using namespace std; #include<iostream> #include<math.h> int main() { int p,t; float r,si,ci,amt1,amt2; cout<<"Enter the Principal amount : "; cin>>p; cout<<"Enter the Time period : "; cin>>t; cout<<"Enter the Rate of interest : "; cin>>r; si = p*t*r/100; amt1 = p + si; amt2 = p*pow((1+r/100),t); ci = amt2 - p; cout<<"====Given Data are ===="<<endl; cout<<"P = "<<p<<endl; cout<<"T = "<<t<<endl; cout<<"R = "<<r<<endl; cout<<"============ output =========="<<endl; cout<<"Simple interest = "<<si<<" Total Amt = "<<amt1<<endl; cout<<"compound interest = "<<ci<<" Total Amt = "<<amt2<<endl; return 0; }
Output :-