# C++ Program to Calculate simple interest and compound interest

After calculating interest on the principal amount, simple interest is calculated by taking the principal amount, the rate of interest, and the number of years it will take to calculate interest. The formula is quite easy to understand. The power law is used to calculate compound interest by taking into account the principal amount, the rate of interest, and the period. Here, the formula is likewise not difficult. In this article, we'll talk about how to calculate simple and compound interest values and then use the C++ programming language to put this logic into practice.

## Simple Interest

Simple interest is a way to find out how much interest will be charged on a principal amount of money at a specific rate and for a specific duration of time. The formula is given below −

$$SI\:=\:\frac{P\times\:T\times\:R}{100}$$

Where,

P : Principal Amount,

T : Time,

R : Rate of interest in percentage per annum.

## Algorithm

• Take inputs P: The principal amount, T: time in years, R: Rate of interest.
• Calculate SI = (P.T.R)/100.
• Display the amount we will get as interest SI.
• The total amount will be (P + SI).

## Example

#include <iostream>
using namespace std;

float solve( int P, int T, float R ) {
float si;
si = (P * T * R) / 100;
return si;
}

int main() {
int P = 10000;
int T = 7;
float R = 6.25;
cout << "Simple interest for 10,000 with ROI 6.25\% for 7 years is: ";
float result;
result = solve( P, T, R );
cout << result << endl;
cout << "Total amount is: " << P + result;
return 0;
}


## Output

Simple interest for 10,000 with ROI 6.25% for 7 years is: 4375
Total amount is: 14375


## Compound Interest

Compound interest is another type of interest calculating method, where we add the interest of one year's principal to the next year's principal to compute interest, unlike the principal amount in simple interest, here it does not remain constant.

$$FA\:=\:P\left(1\:+\:\frac{R}{N*100}\right)^{NT}$$

where,

FA = Final Amount

P : Initial Principal Amount,

T : Time,

N = Number of the times the interest is applied during T,

R : Rate of interest

## Algorithm

• Take inputs P: The principal amount, T: time in years, R: Rate of interest, N: Number of times the interest is being considered in the T period.
• Calculate FA = P * (1 + (R/(N*100)))^(NT)
• Display the amount we will get extra is (FA – P)
• Final amount FA

## Example

#include <iostream>
#include <cmath>
using namespace std;

float solve( int P, int T, float R, int N) {
float fa;
fa = P * pow((1 + ( R / (N * 100) )), ( N * T ));
return fa - P;
}

int main() {
int P = 10000;
int T = 7;
float R = 6.25;
int N = 4;
cout << "Compound interest for 10,000 with ROI 6.25\% for 7 years and calculating interests quarterly, is: ";
float result;
result = solve( P, T, R, N);
cout << result << endl;
cout << "Total amount is: " << P + result;
return 0;
}


## Output

Compound interest for 10,000 with ROI 6.25% for 7 years and calculating interests quarterly, is: 5436
Total amount is: 15436


## Conclusion

Calculating interests for a given principal amount with duration and rate of interest is an easy process. There are two different interest systems discussed in this article. In the first method, we are calculating the simple interest method which computes interest after the whole period and a constant amount is added to the principal amount at the end. Compound interest on the other hand is cyclic. Here, the interest is added with the principal amount every year, and each year is divided into several sections. In this article, these two methods are implemented using C++ language.

Updated on: 17-Oct-2022

11K+ Views 