C++ | Gross salary

Introduction

The program to calculate gross salary. The first one , the next and the last one is same but little modifications are existing. In the first, All outputs including da and hra are shown. In next only gross salary is shown. The last one also shows only gross salary but the formula is shorten. Go enjoy the program. Lets begin………..

Program for gross salary

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
int b;
float da,hra,gsal;
//Input basic salary save it in 'b'
cout<<"Enter the Basic salary"<<endl;
cin>>b;
//calculate gross salary and save them in 'gsal'
da=0.4*b;
hra=0.2*b;
gsal=b
+da+hra;
//show the output
cout<<"da is "<<da<<endl;
cout<<"hra is "<<hra<<endl;
cout<<"gross salary is "<<gsal<<endl;
//get character
getch();
}

Output

Enter the Basic salary
2000
da is 800
hra is 400
gross salary is 3200

or you can do other way

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
int b;
float d,h,gsal;
//Input basic salary save it in 'b'
cout<<"Enter the Basic salary"<<endl;
cin>>b;
//calculate gross salary and save them in 'gsal'
d=0.4*b;
h=0.2*b;
gsal=b+da+hra;
//show the output
cout<<"gross salary is "<<gsal<<endl;
//get character
getch();
}

Output

Enter the Basic salary
2000
gross salary is 3200

Or the by making formula more shorter……

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
int b;
float gsal;
//Input basic salary save it in 'b'
cout<<"Enter the Basic salary"<<endl;
cin>>b;
//calculate gross salary and save them in 'gsal'
gsal=b+(0.4*b)+(0.2*b);
//show the output
cout<<"gross salary is "<<gsal<<endl;
//get character
getch();
}

Output

Enter the Basic salary
2000
gross salary is 3200

How does it work

  1. You enter the basic salary for calculation and is saved in variables.
  2. The da is calculated according to da  formula and is saved in ‘da’.
  3. The hra is calculated according to hra formula and is saved in ‘hra’.
  4. The gross salary is calculated according to formula and is saved in ‘gsal’
  5. Variable ‘gsal’ is shown by cout.

Extending it

The program cannot be extended. There are no direction in which you can extend. So you cannot extend the program.

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 and int.(name the as you want.)
  5. Add cout and cin of variable of basic salary.(as shown in program)
  6. Calculate the da of  the variables and save them in ‘da’ variable.
  7. Calculate the hra of  the variables and save them in ‘hra’ variable.
  8. Calculate the gross salary of  the variables and save them in ‘gsal’ variable.
  9. Cout the ‘gsal’ variable.

At the end

You learnt creating the c++ program of Gross salary. 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