Course offer · HLD · LLD · System Design at ₹799 until 30 Nov (not interview packs)

Calculate Simple Interest in C++

Calculate simple interest and the total amount in C++ using P * R * T / 100. Explains why the rate is a percent, why float is used, and how to check your answer.

BeginnerBasic ProgramsExample 10 of 14
calculate-simple-interest.cpp
1#include <iostream>
2#include <iomanip>
3using namespace std;
4
5int main() {
6 float principal, rate, time, interest;
7
8 cout << "Enter principal amount: ";
9 cin >> principal;
10
11 cout << "Enter rate of interest (per year): ";
12 cin >> rate;
13
14 cout << "Enter time (in years): ";
15 cin >> time;
16
17 // Simple Interest = (P * R * T) / 100
18 interest = (principal * rate * time) / 100;
19
20 cout << fixed << setprecision(2);
21 cout << "Simple Interest = " << interest << endl;
22 cout << "Total Amount = " << principal + interest << endl;
23
24 return 0;
25}

Sample Output

Simple Interest = 1000.00

10000 × 5 × 2 / 100.

Total Amount = 11000.00

Principal plus interest.

In this one

  • How to code the simple interest formula
  • Why the rate is entered as a percent like 5, not 0.05
  • How the total amount is principal plus interest
  • How float avoids integer truncation

How it works

  1. 1

    Read principal, rate, and time as float.

  2. 2

    Multiply principal * rate * time.

  3. 3

    Divide by 100 because rate is a percentage.

  4. 4

    Print interest and principal + interest with two decimals.

Edge cases

Rate entered as a decimal

Enter 0.05 for the rate.

The formula divides by 100 again, so interest becomes 10 instead of 1000. The prompt expects a percent.

Time in months

Enter 6 for six months.

The program treats 6 as six years. Convert months to years first: 6 / 12.0 = 0.5.

What's going on

Simple interest in C++ is P * R * T / 100. Rate 5 means five percent, not 0.05.

float principal, rate, time, interest;

float (or double) so 10000 * 5 * 2 / 100 keeps the tenths. The same formula in int truncates.

cin >> principal; then rate, then time.

Sample: 10000, 5, 2.

interest = (principal * rate * time) / 100;

10000 * 5 * 2 / 100 = 1000. That's the sample. Total amount is principal + interest = 11000.

Enter 0.05 for the rate and the result is 100× too small (10 instead of 1000). The prompt says "per year" as a percent.

cout << fixed << setprecision(2);

Two digits after the dot, same as the float-multiplication program. Needs <iomanip>.

Sanity check: 1000 at 5% for 2 years is 100. If that isn't what you get, the rate interpretation is wrong.

This is not compound interest. Compound uses a power — that's the next program.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

P = 2000, R = 10, T = 3. What is the simple interest?

Pick an answer to check it.

Question 2

What happens if principal, rate, and time are int and P*R*T is 150?

Pick an answer to check it.

Questions people ask

What is the difference between simple and compound interest?

Simple interest is calculated only on the original principal. Compound interest also earns interest on interest already added.

Why divide by 100?

Because R is a percentage. 5% means 5 out of 100.

Should money use float?

For a classroom formula it is fine. Real banking software stores money in whole units like paise to avoid rounding drift.