Skip to main content

Program to calculate compound interest in c++

C++ Program to calculate compound interest. Here more solutions.

// Include header file
#include <iostream>
#include <math.h>
using namespace std;

// C++ program for
// Calculate compound interest

// Method which is take three parameters
// And calculates that compound interest
// Here time is form in year
// rate is form of annual interest rate
void compoundInterest(double principal, 
                      double time, 
                      double rate) {
    // Display parameters values
    cout << "Principal : "  << principal << endl;
    cout << "Time : "  << time << endl;
    cout << "Rate : "  << rate << endl;
    // Calculate interest
    double amount = principal * (pow((1 + rate / 100),time));
    // Display amount
    cout << "Compound Interest : " << amount << endl << endl ;
}

int main() {
    // Test Cases
    // Send principal,time and rate
    compoundInterest(1500, 3, 7.3);
    compoundInterest(170.4, 7, 3.4);
    return 0 ;
}

Output

Principal : 1500
Time : 3
Rate : 7.3
Compound Interest : 1853.06

Principal : 170.4
Time : 7
Rate : 3.4
Compound Interest : 215.334




Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment