C program code for salary calculation - Feel Educated-feel the real taste of education

Breaking

Thursday, September 19, 2024

C program code for salary calculation

 #include <stdio.h>


int main() {

    float sal, DA, HRA, Conveyance, Medical, Bonus, LTA;

    float income_tax, gpf;

    char choice;

    float percentage;

    float amount;


    printf("Enter your Basic Salary: ");

    scanf("%f", &sal);


    while (getchar() != '\n');


    // Function to handle allowances

    printf("Enter your House Rent Allowance:\n");

    printf("If in percentage, press 'p'\n");

    printf("If in digits, press 'n'\n");

    printf("Your choice: ");

    scanf("%c", &choice);


    if (choice == 'p') {

        printf("Enter percentage: ");

        scanf("%f", &percentage);

        HRA = (sal / 100) * percentage;

    } else if (choice == 'n') {

        printf("Enter amount: ");

        scanf("%f", &amount);

        HRA = amount;

    } else {

        HRA = 0;

        printf("Invalid choice for House Rent Allowance.\n");

    }


    while (getchar() != '\n');


    printf("Enter your Conveyance Allowance:\n");

    printf("If in percentage, press 'p'\n");

    printf("If in digits, press 'n'\n");

    printf("Your choice: ");

    scanf("%c", &choice);


    if (choice == 'p') {

        printf("Enter percentage: ");

        scanf("%f", &percentage);

        Conveyance = (sal / 100) * percentage;

    } else if (choice == 'n') {

        printf("Enter amount: ");

        scanf("%f", &amount);

        Conveyance = amount;

    } else {

        Conveyance = 0;

        printf("Invalid choice for Conveyance Allowance.\n");

    }


    while (getchar() != '\n');


    printf("Enter your Medical Allowance:\n");

    printf("If in percentage, press 'p'\n");

    printf("If in digits, press 'n'\n");

    printf("Your choice: ");

    scanf("%c", &choice);


    if (choice == 'p') {

        printf("Enter percentage: ");

        scanf("%f", &percentage);

        Medical = (sal / 100) * percentage;

    } else if (choice == 'n') {

        printf("Enter amount: ");

        scanf("%f", &amount);

        Medical = amount;

    } else {

        Medical = 0;

        printf("Invalid choice for Medical Allowance.\n");

    }


    while (getchar() != '\n');


    printf("Enter your Performance Bonus:\n");

    printf("If in percentage, press 'p'\n");

    printf("If in digits, press 'n'\n");

    printf("Your choice: ");

    scanf("%c", &choice);


    if (choice == 'p') {

        printf("Enter percentage: ");

        scanf("%f", &percentage);

        Bonus = (sal / 100) * percentage;

    } else if (choice == 'n') {

        printf("Enter amount: ");

        scanf("%f", &amount);

        Bonus = amount;

    } else {

        Bonus = 0;

        printf("Invalid choice for Performance Bonus.\n");

    }


    while (getchar() != '\n');


    printf("Enter your Leave Travel Allowance:\n");

    printf("If in percentage, press 'p'\n");

    printf("If in digits, press 'n'\n");

    printf("Your choice: ");

    scanf("%c", &choice);


    if (choice == 'p') {

        printf("Enter percentage: ");

        scanf("%f", &percentage);

        LTA = (sal / 100) * percentage;

    } else if (choice == 'n') {

        printf("Enter amount: ");

        scanf("%f", &amount);

        LTA = amount;

    } else {

        LTA = 0;

        printf("Invalid choice for Leave Travel Allowance.\n");

    }


    while (getchar() != '\n');


    printf("Enter your Dearness Allowance:\n");

    printf("If in percentage, press 'p'\n");

    printf("If in digits, press 'n'\n");

    printf("Your choice: ");

    scanf("%c", &choice);


    if (choice == 'p') {

        printf("Enter percentage: ");

        scanf("%f", &percentage);

        DA = (sal / 100) * percentage;

    } else if (choice == 'n') {

        printf("Enter amount: ");

        scanf("%f", &amount);

        DA = amount;

    } else {

        DA = 0;

        printf("Invalid choice for Dearness Allowance.\n");

    }


    while (getchar() != '\n');


    printf("Enter your Income Tax Deduction:\n");

    printf("If in percentage, press 'p'\n");

    printf("If in digits, press 'n'\n");

    printf("Your choice: ");

    scanf("%c", &choice);


    if (choice == 'p') {

        printf("Enter percentage: ");

        scanf("%f", &percentage);

        income_tax = (sal / 100) * percentage;

    } else if (choice == 'n') {

        printf("Enter amount: ");

        scanf("%f", &amount);

        income_tax = amount;

    } else {

        income_tax = 0;

        printf("Invalid choice for Income Tax Deduction.\n");

    }


    while (getchar() != '\n');


    printf("Enter your General Provident Fund (GPF) Deduction:\n");

    printf("If in percentage, press 'p'\n");

    printf("If in digits, press 'n'\n");

    printf("Your choice: ");

    scanf("%c", &choice);


    if (choice == 'p') {

        printf("Enter percentage: ");

        scanf("%f", &percentage);

        gpf = (sal / 100) * percentage;

    } else if (choice == 'n') {

        printf("Enter amount: ");

        scanf("%f", &amount);

        gpf = amount;

    } else {

        gpf = 0;

        printf("Invalid choice for GPF Deduction.\n");

    }


    float total_allowances = HRA + Conveyance + Medical + Bonus + LTA + DA;

    float total_deductions = income_tax + gpf;

    float total_salary = sal + total_allowances - total_deductions;


    printf("\nSalary Details:\n");

    printf("Basic Salary: %.2f\n", sal);

    printf("House Rent Allowance: %.2f\n", HRA);

    printf("Conveyance Allowance: %.2f\n", Conveyance);

    printf("Medical Allowance: %.2f\n", Medical);

    printf("Performance Bonus: %.2f\n", Bonus);

    printf("Leave Travel Allowance: %.2f\n", LTA);

    printf("Dearness Allowance: %.2f\n", DA);

    printf("Income Tax Deduction: %.2f\n", income_tax);

    printf("General Provident Fund (GPF) Deduction: %.2f\n", gpf);

    printf("Total Allowances: %.2f\n", total_allowances);

    printf("Total Deductions: %.2f\n", total_deductions);

    printf("Net Salary: %.2f\n", total_salary);

    if(total_salary>sal){

    printf("! No need to calculate your salary ! You are Bankrupt");

}


    return 0;

}