C proggramming : Wrong output in calculations

The work year bonus of following code is not displayed correctly. And the total is not calculated properly. The code works fine, with no apparent errors but displays wrong outputs. Anybody know the reason why?

#include<stdio.h>
int main()
{
    int GrossRem,WorkInBonus,MonthlyBonus,sales,Years,AddAllow,Bsalary;
    char workIn;

    printf ("Enter basic salary : ");
    scanf ("%d",&Bsalary);
    printf ("Enter years of service : ");
    scanf ("%d",&Years);
    printf ("Enter monthly sales : ");
    scanf ("%d",&sales);
    printf ("Enter 'L' if work in Lima, or N if not : ");
    scanf ("%s",&workIn);

    printf ("\n\n");

    if (sales<1000)
        MonthlyBonus=(sales*10)/100;
    else if (sales<2000)
        MonthlyBonus=(sales*15)/100;
    else
        MonthlyBonus=(sales*20)/100;

    if (Years>4)
        AddAllow=(Bsalary*10)/100;
    else
        AddAllow=0;


    if (workIn=='L')
        WorkInBonus=500;
    else
        WorkInBonus=0;

    printf ("Work year bonus : %d \n",AddAllow);
    printf ("Monthly sales bonus : %d \n",MonthlyBonus);
    printf ("Work in Lima bonus : %d \n",WorkInBonus);
    GrossRem = AddAllow+WorkInBonus+MonthlyBonus+Bsalary;
    printf ("Gross remuneration : %d \n",GrossRem);

    return 0;
}
1 Like
#include<stdio.h> 
int main()
{
    float Basic,GrossRem,WorkInBonus,MonthlyBonus,sales,Years,AddAllow;
    char workIn;
                    printf ("Enter basic salary : ");
                    scanf ("%f",&Basic);
                    printf ("Enter years of service : ");
                    scanf ("%f",&Years);
                    printf ("Enter monthly sales : ");
                    scanf ("%f",&sales);
                    printf ("Enter 'L' if work in Lima, or N if not : ");
                    scanf ("%s",&workIn);
                    printf ("\n\n");
                //the monthly bonus is calculated according to the sales amount
                    if (sales<1000)
                        MonthlyBonus=(sales*0.10);
                    else if (sales<2000)
                        MonthlyBonus=(sales*0.15);
                    else if(sales>=2000)
                        MonthlyBonus=(sales*0.20);
                    else
                        MonthlyBonus=0;
                //an additional allowance is provided if work years are over 4
                    if (Years>4){
                        AddAllow=(Basic*0.10);
                    }else{
                        AddAllow=0;}
               // if work in Lima, enter L and a bonus is added
                    if (workIn=='L')
                        WorkInBonus=500;
                    else
                        WorkInBonus=0;

                //Gross remuneration is the addition of bonuses and basic salary together

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

                    printf ("Monthly sales bonus : %.2f \n",MonthlyBonus);

                    printf ("Work in Lima bonus : %.2f \n",WorkInBonus);

                    GrossRem = AddAllow+WorkInBonus+MonthlyBonus+Basic;

                    printf ("Gross remuneration : %.2f \n",GrossRem);



    return 0;

}
1 Like