Simple & Compound Interest with Tiered Bonus Rate
Problem Statement
Given Principal (P), annual interest rate (R), and time in years (T), calculate both Simple Interest (SI) and annually compounded Compound Interest (CI). If tenure T > 5 years, apply an additional 2% loyalty bonus rate.
Variable Dictionary / Table
| Variable Name | Data Type | Role & Purpose |
|---|---|---|
| P, R, T | Float / Double | Principal amount, Base rate %, Time period |
| effectiveRate | Float / Double | R + 2% if T > 5, else R |
| SI, CI | Float / Double | Calculated interest amounts |
Step-by-Step Formal Algorithm
Step 1: Start.
Step 2: Read Principal P, Base Rate R, Time T.
Step 3: If P <= 0 or R <= 0 or T <= 0:
Print 'Invalid input parameters' and Stop.
Step 4: If T > 5:
effectiveRate = R + 2
Step 5: Else:
effectiveRate = R
Step 6: Compute SI = (P * effectiveRate * T) / 100.
Step 7: Compute CI = P * ((1 + effectiveRate / 100) ^ T) - P.
Step 8: Print effectiveRate, SI, CI.
Step 9: Stop.
Flowchart (Interactive Graphical Diagram)
CI = P * (1 + effectiveRate/100)^T - P"] Base --> Calc Calc --> Out[/"Print SI, CI, effectiveRate"/] Out --> Stop
Flowchart (ANSI Terminal ASCII Chart)
+-----------------+
| [ START ] |
+-----------------+
|
v
+-----------------+
| Read P, R, T |
+-----------------+
|
v
/ \
/Valid Inputs?\ ---NO---> [Print Invalid] --> [STOP]
\ /
| YES
v
/ \
/ T > 5 ? \ ---YES--> [effectiveRate = R + 2]
\ / |
| NO |
v |
+--------------------+ |
| effectiveRate = R | |
+--------------------+ |
| |
+--------------+---------------+
|
v
+---------------------------------------+
| SI = P * effectiveRate * T / 100 |
| CI = P * (1 + effectiveRate/100)^T - P|
+---------------------------------------+
|
v
+---------------------------------------+
| Print SI, CI, effectiveRate |
+---------------------------------------+
|
v
[ STOP ]
Dry-Run Execution Trace Table
| Execution Step / Case | Variables State 1 | Variables State 2 | Condition Evaluation | Output / Result |
|---|---|---|---|---|
| Short Term (T=3) | P=10000, R=8%, T=3 | effectiveRate=8% | SI=2400, CI=2597.12 | SI=$2,400.00, CI=$2,597.12 |
| Long Term (T=6) | P=10000, R=8%, T=6 | effectiveRate=10% (+2% bonus) | SI=6000, CI=7715.61 | SI=$6,000.00, CI=$7,715.61 |
Interactive C++ Compiler & Runner
Live In-BrowserEdit the code directly with the Edit Code button, provide custom inputs, and press Run Code to compile and execute in the live terminal console below!
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
double P, R, T;
cout << "Enter Principal (P), Base Rate % (R), Time in years (T): ";
if (!(cin >> P >> R >> T) || P <= 0 || R <= 0 || T <= 0) {
cout << "Invalid inputs! P, R, and T must be strictly positive.\n";
return 1;
}
double effectiveRate = (T > 5.0) ? (R + 2.0) : R;
double SI = (P * effectiveRate * T) / 100.0;
double CI = P * pow(1.0 + (effectiveRate / 100.0), T) - P;
cout << fixed << setprecision(2);
cout << "\n========================================\n";
cout << " FINANCIAL INTEREST CALCULATION REPORT\n";
cout << "========================================\n";
cout << "Principal (P) : $" << P << "\n";
cout << "Base Rate : " << R << "%\n";
cout << "Tenure (T) : " << T << " years\n";
cout << "Effective Rate : " << effectiveRate << "%"
<< (T > 5.0 ? " (+2% Long-Term Loyalty Bonus)" : "") << "\n";
cout << "----------------------------------------\n";
cout << "Simple Interest (SI) : $" << SI << " (Total: $" << (P + SI) << ")\n";
cout << "Compound Interest(CI): $" << CI << " (Total: $" << (P + CI) << ")\n";
cout << "Compounding Edge : +$" << (CI - SI) << "\n";
cout << "========================================\n";
return 0;
}
Input: 10000 8 6 Output: ======================================== FINANCIAL INTEREST CALCULATION REPORT ======================================== Principal (P) : $10000.00 Base Rate : 8.00% Tenure (T) : 6.00 years Effective Rate : 10.00% (+2% Long-Term Loyalty Bonus) ---------------------------------------- Simple Interest (SI) : $6000.00 (Total: $16000.00) Compound Interest(CI): $7715.61 (Total: $17715.61) Compounding Edge : +$1715.61 ========================================
Compound Interest demonstrates the exponential power of compounding, earning $1,715.61 more than simple interest on a 6-year $10,000 deposit at 10%.