Salary Calculation using IF Statement in C++


This program takes an input of basic salary from the user and then calculates the gross salary based on a set of conditions. The program first asks the user to enter their basic salary and reads in the input using the "cin" statement.

Next, the program checks if the basic salary is less than 1500. If it is, then the program calculates the House Rent Allowance (HRA) and Dearness Allowance (DA) based on the formula HRA = 10% of basic salary and DA = 90% of basic salary. If the basic salary is greater than or equal to 1500, then the program sets the HRA to a fixed value of 500 and calculates the DA as 98% of the basic salary.

After calculating the HRA and DA, the program calculates the gross salary by adding the basic salary, HRA, and DA together. Finally, the program outputs the basic salary, HRA, DA, and gross salary to the console using the "cout" statement. At the end of the program, it returns 0 to indicate successful execution.

Source Code

/*
If his basic salary is less than Rs. 1500,
then HRA = 10% of basic salary and DA = 90% of basic salary.
If his salary is either equal to or above Rs. 1500,
then HRA = Rs. 500 and DA = 98% of basic salary.
If the employee's salary is input through the keyboard
write a program to find his gross salary
*/
 
#include<iostream>
using namespace std;
int main()
{
    float bs,gs,da,hra;
    cout<<"\nEnter Your Basic Salary : ";
    cin>>bs;
    if(bs<1500)
    {
        hra=bs*10/100;
        da=bs*90/100;
    }
    else
    {
        hra=500;
        da=bs*98/100;
    }
    gs=bs+hra+da;
    cout<<"\nBasic Salary    :"<<bs;
    cout<<"\nHRA             :"<<hra;
    cout<<"\nDA              :"<<da;
    cout<<"\n---------------------------";
    cout<<"\nGross Salary    :"<<gs;
    return 0;
}
 

Output

Enter Your Basic Salary : 15000

Basic Salary    :15000
HRA             :500
DA              :14700
---------------------------
Gross Salary    :30200
To download raw file Click Here

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples