Calculate Simple Interest

Beginner-friendly C++ program that reads principal, rate, and time to calculate simple interest and total amount payable.

BeginnerTopic: Basic Programs
Back

C++ Calculate Simple Interest Program

This program helps you to learn the fundamental structure and syntax of C++ programming.

Try This Code
#include <iostream>
                  #include <iomanip>
                  using namespace std;
                  
                  int main() {
                      float principal, rate, time, interest;
                      
                      cout << "Enter principal amount: ";
                      cin >> principal;
                      
                      cout << "Enter rate of interest (per year): ";
                      cin >> rate;
                      
                      cout << "Enter time (in years): ";
                      cin >> time;
                      
                      // Simple Interest = (P * R * T) / 100
                      interest = (principal * rate * time) / 100;
                      
                      cout << fixed << setprecision(2);
                      cout << "Simple Interest = " << interest << endl;
                      cout << "Total Amount = " << principal + interest << endl;
                      
                      return 0;
                  }
Output
Enter principal amount: 10000
                  Enter rate of interest (per year): 5
                  Enter time (in years): 2
                  Simple Interest = 1000.00
                  Total Amount = 11000.00

Understanding Calculate Simple Interest

This program teaches you how to calculate simple interest using a mathematical formula. This is a very common calculation in banking, finance, and school mathematics. The program takes the principal amount, rate of interest, and time from the user. Then it calculates the interest and shows the total amount to be paid.

---

1. Understanding Simple Interest

Simple Interest (SI) is a method used to calculate interest on a fixed principal amount.

The formula is:

SI = (P × R × T) / 100

Where:

P = Principal (the money you borrow or invest)
R = Rate of interest per year
T = Time in years

Example:

If you invest ₹10,000 at 5% for 2 years:

SI = (10000 × 5 × 2) / 100 = 1000

Total Amount = Principal + Interest = 11000

---

2. Header Files Used

1.#include <iostream>

Needed for cin (input) and cout (output).

2.#include <iomanip>

Provides setprecision() and fixed for formatting decimal output.

---

3. Declaring Float Variables

The program declares:

float principal, rate, time, interest;

We use float because financial values often include decimals.

Each variable stores:

principal → initial amount of money
rate → interest rate (percentage per year)
time → duration in years
interest → calculated simple interest

---

4. Taking Input From the User

The program asks the user to enter:

Principal
Interest rate
Time in years

Each value is stored in its respective variable using cin.

Example:

Enter principal amount: 10000 → principal = 10000
Enter rate: 5 → rate = 5
Enter time: 2 → time = 2

---

5. Applying the Simple Interest Formula

The formula is applied as:

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

This calculates the interest using the user-provided values.

---

6. Formatting the Output

To make the result clean and readable, the program uses:

This ensures:

Numbers are displayed in normal decimal format
Exactly 2 digits appear after the decimal

So 1000 becomes 1000.00

and 11000 becomes 11000.00

This is very useful in finance calculations.

---

                  cout << fixed << setprecision(2);

7. Displaying the Results

The program prints:

Simple Interest
Total Amount (Principal + Interest)

Example output:

Simple Interest = 1000.00

Total Amount = 11000.00

---

8. Program Completion

---

return 0 ends the program successfully.

Summary

The program uses the simple interest formula.
It reads principal, rate, and time from the user.
It calculates the interest and total amount.
setprecision(2) ensures neat, professional output.
This is a perfect beginner program combining input, arithmetic, and formatted output.

This example strengthens the understanding of formulas, variables, and basic financial calculations in C++.

Let us now understand every line and the components of the above program.

Note: To write and run C++ programs, you need to set up the local environment on your computer. Refer to the complete article Setting up C++ Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your C++ programs.

Practical Learning Notes for Calculate Simple Interest

This C++ program is part of the "Basic Programs" topic and is designed to help you build real problem-solving confidence, not just memorize syntax. Start by understanding the goal of the program in plain language, then trace the logic line by line with a custom input of your own. Once you can predict the output before running the code, your understanding becomes much stronger.

A reliable practice pattern is to run the original version first, then modify only one condition or variable at a time. Observe how that single change affects control flow and output. This deliberate style helps you understand loops, conditions, and data movement much faster than copying full solutions repeatedly.

For interview preparation, explain this solution in three layers: the high-level approach, the step-by-step execution, and the time-space tradeoff. If you can teach these three layers clearly, you are ready to solve close variations of this problem under time pressure.

Table of Contents