Write a program that inputs principal amount, rate of interest and total time. It calculates the compound interest and displays it.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#include <iostream> #include <cmath> using namespace std; double calculateCompoundInterest(double principal, double rate, double time) { double amount = principal * pow((1 + rate / 100), time); double compoundInterest = amount - principal; return compoundInterest; } int main() { double principalAmount, rateOfInterest, timePeriod; // Input principal amount, rate of interest, and time cout
<< "Enter the principal amount: "; cin >> principalAmount; cout << "Enter the rate of interest (in percentage): "; cin >> rateOfInterest; cout << "Enter the time period (in years): "; cin >> timePeriod; // Calculate compound interest double interest = calculateCompoundInterest(principalAmount, rateOfInterest, timePeriod); // Display the calculated compound interest cout << "Compound interest after " << timePeriod << " years: " << interest
<< endl; return 0; } |

**Output**

Enter the principal amount: 3

Enter the rate of interest (in percentage): 4

Enter the time period (in years): 5

Compound interest after 5 years: 0.649959