In this post, we will be learning how to write a C++ Program to Calculate Simple Interest of the given values of Principle, Time and Rate.
The formula to Calculate Simple Interest
To calculate S.I, we have a formula:
1 2 3 4 5 6 7 8 |
S.I = (P*R*T)/100 Where, S.I represents Simple Interest, P represents Principle, R represents Rate (annually), T represents Time (in years). |
Code:
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 |
#include <iostream> using namespace std; int main() { float p; float r; float t; // Taking an input for principle cout << "Enter the principle: "; cin >> p; // Taking an input for rate per year cout << "Enter the rate: "; cin >> r; // Taking an input for time cout << "Enter the time(In Year): "; cin >> t; // formula for S.I. is (p*r*t)/100 float si = (p*r*t)/100; // printing the simple interest cout << "The Simple Interest is " << si << endl; return 0; } |
Output:
1 2 3 |
Enter the principle: 500 Enter the rate: 5 Enter the time(In Year): 3 The Simple Interest is 75 |