dimanche 7 novembre 2021

Why is this C code returning 0 instead of deductions? Please mention any other errors too

I am very new to programming, I wrote this if-else ladder code to print total deductions But the output is 0. There are 7 employees with the salaries mentioned in the array. The if-else ladder is checking the range of salary and accordingly finding out deduction. t is storing the total deductions.

// Total Tax Deduction
#include<stdio.h>
int main() {
    int s,d,t;
    int employees[7] = {155350,135600,96000,87000,80000,60000,57300};
    int const SIZE=7;
    t=0;
    for (int i = 0; i < SIZE; i++) {
        s=employees[i];
    
        if(s>=100000) {
            d=s*(20/100);
        }

        else if (90000<=s<100000) {
            d=s*(15/100);
        }

        else if (70000<=s<90000) {
            d=s*(10/100);
        }

        else if (50000<=s<70000) {
            d=s*(5/100);
        }

        else {
            d=0;
        }

        t+=d;

    }

    printf("Monthly Total Deduction: %d ", t);

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire