cplusplus
cplusplus

 

Introduction

Simple Interest is a quick and easy method to calculate the interest charged or earned on a principal sum of money. It is commonly used in financial transactions such as loans or savings accounts.

The formula for calculating simple interest is:

Simple Interest (SI) = (P × R × T) / 100

Where:

  • P = Principal amount (the initial sum of money)
  • R = Rate of interest per annum
  • T = Time period for which the money is borrowed or invested, in years

This program allows you to calculate the simple interest based on the principal amount, the rate of interest, and the time period.

Objective

The objective of this program is to write a C++ code that will:

  • Prompt the user to enter the principal amount, rate of interest, and time period.
  • Calculate the simple interest using the provided formula.
  • Display the calculated interest to the user.

C++ Code


#include 
using namespace std;

int main() {
    // Declare variables
    float principal, rate, time, simpleInterest;

    // User input for principal amount, rate of interest, and time
    cout << "Enter the Principal amount: "; cin >> principal;
    cout << "Enter the Rate of interest (in percentage): "; cin >> rate;
    cout << "Enter the Time period (in years): "; cin >> time;

    // Calculate Simple Interest using the formula: SI = (P * R * T) / 100
    simpleInterest = (principal * rate * time) / 100;

    // Output the result
    cout << "The Simple Interest is: " << simpleInterest << endl;

    return 0;
}

Explanation of the Program Structure

The program follows a simple structure and flow:

  1. Variable Declaration: Four variables are declared: principal, rate, time, and simpleInterest to store user input and calculated results.
  2. Taking User Input: The program asks the user to input the principal amount, rate of interest (in percentage), and time period (in years). These values are stored in the respective variables using cin.
  3. Simple Interest Calculation: The program calculates the simple interest using the formula: SI = (P × R × T) / 100. The result is stored in the simpleInterest variable.
  4. Output: Finally, the program outputs the calculated simple interest using cout for the user to see the result.

How to Run the Program

    1. First, write the C++ code in a text editor such as Visual Studio Code, Code::Blocks, or any IDE that supports C++.
    2. Save the file with a .cpp extension (e.g., simple_interest.cpp).
    3. Open a terminal or command prompt and navigate to the folder where the file is saved.
    4. Compile the code using a C++ compiler such as g++ (or any available compiler) by typing:
g++ simple_interest.cpp -o simple_interest
    1. Run the program by typing the following command in the terminal:
./simple_interest
  1. The program will prompt you to enter the principal, rate, and time. After entering these values, it will display the calculated simple interest.

 

By Aditya Bhuyan

I work as a cloud specialist. In addition to being an architect and SRE specialist, I work as a cloud engineer and developer. I have assisted my clients in converting their antiquated programmes into contemporary microservices that operate on various cloud computing platforms such as AWS, GCP, Azure, or VMware Tanzu, as well as orchestration systems such as Docker Swarm or Kubernetes. For over twenty years, I have been employed in the IT sector as a Java developer, J2EE architect, scrum master, and instructor. I write about Cloud Native and Cloud often. Bangalore, India is where my family and I call home. I maintain my physical and mental fitness by doing a lot of yoga and meditation.

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)