Resources » Education » Languages » Computer languages

C and C++ program to calculate simple interest.

Updated: Category: Computer languages

In this article I am going to write and explain a simple C++ program to calculate simple interest. It also contains step by step explanation of the whole programming concept. The detailed step by step explanation of the program will clear most of the programming concepts of C++. I hope you will enjoy it.

About the program

This is a C++ program, which makes use of some functions to calculate simple interest when some required information is given by the user. User has to input principle amount(p), rate of interest(r) and time period for simple interest(t). On using these information by the user, program calculate the simple interest.

Coding of the program

The coding of the program goes as follows :

void main()
int p,r,t;
float i;
cout<<"Enter the principle amount:"
cout<<"\nEnter the rate of interest:"
cout<<"\nEnter the time period for interest:"
cout<<"The interest for the above input data is:"<< i;


Step by step explanation:

The above coding can be explained as follows:

  • The first step to any c++ program is header file inclusion. Here we have included two header files, namely "iostream.h" and "conio.h". As clear from the name, header file iostream.h contains inout/output stream functions. Since we have used cout and cin function in the program so we have included iostream.h. Similarly "conio.h" is a header file which is included as it contains two important functions used in the program clrscr() and getch()

  • The second step is to write the body of the program which starts from main function. In c++ main() is the vital component of any program. No program can be made without the use of main() function.

  • Now after the main function we define variables or parameters that are required to be used in the program. Since the program is about simple interest, so we have to define variables like principle(p), rate of interest(r), time period(t) and finally interest(i).

  • Now writing the logic of the program. In this program, the logic is the formula of simple interest itself. And hence we have written the formula.

  • Now the remaining coding of the program is written which merely consist of the use of library or user defined functions. In this program we have not used any user defined function. It contains only library functions(clrscr() and getch()). However this program can also be made using user defined function. I shall try to cover the use of user defined function in my other post.

This was a simple C++ program by which we can calculate simple interest on the basis of providing some pre required variables to the program as input. If you have any question regarding C and C++ programming concept or you wish to gain more knowledge about C and C++ programming, you are most welcome my blog C++ forums.

Read related articles: C programming   

Did you like this resource? Share it with your friends and show your love!

Responses to "C and C++ program to calculate simple interest."

Post Comment:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    All Rights Reserved.