w3resource

C++ Exercises: Calculate Simple Interest


Simple Interest Calculation

Write a C++ program to enter P, T, R and calculate Simple Interest.

Sample Solution:

C++ Code :

#include<iostream> // Including input-output stream header file
using namespace std; // Using the standard namespace

int main() { // Start of the main function

    int p, r, t, i; // Declaring variables to store principle, rate, time, and interest

    cout << "\n\n Calculate the Simple Interest :\n"; // Displaying the purpose of the program
    cout << " -----------------------------------\n"; 

    cout << " Input the Principle: "; // Prompting the user to input the principle amount
    cin >> p; // Taking input of the principle amount from the user

    cout << " Input the Rate of Interest: "; // Prompting the user to input the rate of interest
    cin >> r; // Taking input of the rate of interest from the user

    cout << " Input the Time: "; // Prompting the user to input the time period
    cin >> t; // Taking input of the time period from the user

    i = (p * r * t) / 100; // Calculating the simple interest using the formula: PRT / 100

    cout << " The Simple interest for the amount " << p << " for " << t << " years @ " << r << " % is: " << i; // Displaying the calculated simple interest

    cout << endl; // Displaying an empty line for better readability
    return 0; // Returning 0 to indicate successful program execution
}

Sample Output:

 Calculate the Simple Interest :                                       
 -----------------------------------                                   
 Input the Principle: 20000                                            
 Input the Rate of Interest: 10                                        
 Input the Time: 1.5                                                   
 The Simple interest for the amount 20000 for 1 years @ 10 % is: 2000

Flowchart:

Flowchart: Calculate Simple Interest

For more Practice: Solve these Related Problems:

  • Write a C++ program to compute simple interest, including error handling for negative principal, rate, or time values.
  • Write a C++ program that calculates simple interest and then outputs a summary report comparing the interest earned over different time periods.
  • Write a C++ program to compute simple interest and then determine the effective annual interest rate from the computed interest.
  • Write a C++ program that accepts principal, rate, and time as inputs, calculates simple interest, and formats the output as a financial report.

Go to:


PREV : Equilateral Triangle Area.
NEXT : Compound Interest Calculation.

C++ Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.