C++ | Calculate simple interest

Introduction

This program will calculate simple interest and the final amount on entered given amount. The first program calculates interest for 1 year @ 9% p.a. which makes it non-flexible. The second calculates for 2 years which is also non-flexible.The third one is for 3 years which is not flexible. But the next one is little flexible which calculates for given number of years. The last one is most flexible due to it calculation of interest on given years and given rate. You can expand the programs by taking more number of years and different rates. Go enjoy the program. Lets begin……

Program to calculate simple interest for 1 year.

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,i,fa;
//Input amount the save it in 'a'
cout<<"Enter the amount"<<endl;
cin>>a;
//calculate interest and final amount and save them in 'i' and 'fa'
i=a*9/100;
fa=a+i;
//show the output
cout<<"Interest @ 9% for 1yr. is "<<i<<endl;
cout<<"Final amount is "<<fa;
//get character
getch();
}

Output

Enter the amount
100
Interest @ 9% for 1yr. is 9
Final amount is 109

Program to calculate simple interest for 2 years.

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,i,fa;
//Input amount the save it in 'a'
cout<<"Enter the amount"<<endl;
cin>>a;
//calculate interest and final amount and save them in 'i' and 'fa'
i=a*9*2/100;
fa=a+i;
//show the output
cout<<"Interest @ 9% for 2yr. is "<<i<<endl;
cout<<"Final amount is "<<fa;
//get character
getch();
}

Output

Enter the amount
100
Interest @ 9% for 2yr. is 18
Final amount is 118

Program to calculate simple interest for 3 year.

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,i,fa;
//Input amount the save it in 'a'
cout<<"Enter the amount"<<endl;
cin>>a;
//calculate interest and final amount and save them in 'i' and 'fa'
i=a*9*3/100;
fa=a+i;
//show the output
cout<<"Interest @ 9% for 3yr. is "<<i<<endl;
cout<<"Final amount is "<<fa;
//get character
getch();
}

Output

Enter the amount
100
Interest @ 9% for 3yr. is 27
Final amount is 127

Program to calculate simple interest for given year.

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,y,i,fa;
//Input amount and year and save them in 'a' and 'y'
cout<<"Enter the amount"<<endl;
cin>>a;
cout<<"Enter the years"<<endl;
cin>>y;
//calculate interest and final amount and save them in 'i' and 'fa'
i=a*9*y/100;
fa=a+i;
//show the output
cout<<"Interest @ 9% is "<<i<<endl;
cout<<"Final amount is "<<fa;
//get character
getch();
}

Output

Enter the amount
100
Enter the years
5
Interest @ 9% for is 45
Final amount is 145

Program to calculate simple interest for given year and given rate

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,y,r,i,fa;
//Input amount and year and save them in 'a' and 'y'
cout<<"Enter the amount"<<endl;
cin>>a;
cout<<"Enter the years"<<endl;
cin>>y;
cout<<"Enter the rate"<<endl;
cin>>r;
//calculate interest and final amount and save them in 'i' and 'fa'
i=a*r*y/100;
fa=a+i;
//show the output
cout<<"Interest is "<<i<<endl;
cout<<"Final amount is "<<fa;
//get character
getch();
}

Output

Enter the amount
100
Enter the years
5
Enter the rate
6
Interest is 30
Final amount is 130

How does it work

  1. You enter the necessary inputs for calculation in and is saved in variables.
  2. The Interest and final amount  is calculated according to formula and is saved in respt. variables.
  3. Variables are shown by cout.

Extending it

The program can be extended by using different years and rates. You can take the necessary inputs and calculate the simple interest.

Explanation.

  1. Include ‘iostream.h’ and ‘conio.h’ files.
  2. Add void main.
  3. Start program by first clearing the screen.
  4. Declare the variables as float (name the as you want.)
  5. Add cout and cin of variables of necessary inputs.(as shown in program)
  6. Calculate the interest of  the variables and save them in respt. variable.
  7. Cout the variables.

At the end

You learnt creating the c++ program of Calculation of Simple interest. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s