-1

Hi everyone I was hoping i could get some help regarding a problem I've been stuck over for the past hour.As far as my understanding of the C is concerned code seems perfectly fine and should work without a hitch.

#include<stdio.h>

void main(){
int salary;
float net_salary;

printf("Please enter your salary.\n");
scanf("%d", &salary);

if(salary >= 2000){
    net_salary = salary - ((7/100)*salary);
    printf("Your net salary is %f." ,net_salary);
}
else if(salary >= 10000 && salary < 20000){
    net_salary = salary - 1000;
    printf("Your net salary is %f.",net_salary);
}

}

The above code returns the following result when I enter 12000 gives the following result.

Please enter your salary.
12000
Your net salary is 12000.000000.

and for 6000 it returns

Please enter your salary.
6000
Your net salary is 6000.000000.

Any help would be greatly appreciated, thank you in advance.

bgbywolf
  • 1
  • 2
  • Edit:- The code takes a user input as the salary and if the salary is greater than 2000 and less than 10000 then 7% of it is deducted for salaries between 10000 and 20000 , 1000 is deducted. The resultant net salary is displayed. – bgbywolf Aug 27 '18 at 15:44

1 Answers1

2

The expression 7/100 is an integer division. It will truncate the result to 0.

If you want a float result, then use 7.0f / 100.0f. Or plain 0.07f.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621