C program to enter basic salary and calculate gross salary of an employee

Write a C program to enter basic salary of an employee and calculate gross salary according to given conditions:
Basic Salary <= 10000 : HRA = 20%, DA = 80%
Basic Salary is between 10001 to 20000 : HRA = 25%, DA = 90%
Basic Salary >= 20001 : HRA = 30%, DA = 95%

How to calculate gross salary of an employee using if else in C programming. Program to calculate gross salary of an employee using if else in C program.

Required knowledge

Basic C programming, If else, Basic mathematics


Program to calculate gross salary

/**
 * C program to calculate gross salary of an employee
 */

#include <stdio.h>

int main()
{
    float basic, gross, da, hra;

    /* Reads basic salary of employee */
    printf("Enter basic salary of an employee: ");
    scanf("%f", &basic);


    /*
     * Calculates D.A and H.R.A according to specified conditions
     */
    if(basic <= 10000)
    {
        da = basic * 0.8;
        hra = basic * 0.2;
    }
    else if(basic <= 20000)
    {
        da = basic * 0.9;
        hra = basic * 0.25;
    }
    else
    {
        da = basic * 0.95;
        hra = basic * 0.3;
    }

    /* Calculates gross salary */
    gross = basic + hra + da;

    printf("GROSS SALARY OF EMPLOYEE = %.2f", gross);

    return 0;
} 


Output
Enter basic salary of an employee: 22000
GROSS SALARY OF EMPLOYEE = 44000.00


Note: %.2f if used to print the gross salary only up to two decimal places. You can also use %f to print fractional values normally up to six decimal places.

Happy coding ;)


Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).

No comments:

Post a Comment