Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Read the gross salary of an employee, then calculates his/her net salary considering:

a. 12% taxes for salaries starting from 1000 LE and more.
b. 10% taxes for salaries starting from 500 LE and below 1000LE.
c. 8% taxes for other salaries.
d. 20 LE Medical care insurance are cut off all employees.

What I have tried:

#include <stdio.h>
int main (){
    int gross;
    int net= gross-20;
    printf("enter your gross salary");
    scanf("%d", &gross);
    if (gross>= 1000){
        net=net-((12/100)*gross);
    }else if (gross>=500 && gross<1000){
        net=net-((10/100)*gross);
    }else{
        net=net-((8/100)*gross);
    }
    printf("your net salary=%d", net);
return 0;
}
Posted
Updated 6-Dec-22 3:03am
Comments
Richard MacCutchan 6-Dec-22 9:00am    
You start by setting net = gross-20;. But gross has not been initialised at this point so net will most likely contain garbage. So do not initialise net until you have read in the gross value.

1 solution

Walk through your code in the debugger:
C++
int gross; // This variable is not initialized here, and will contain a random value...
int net= gross - 20; // ... so this variable is initialized to "some random value" minus 20.
You need to initialize the net variable after you've read the gross variable.

Once you've fixed that, you'll need to fix the integer division[^] in the rest of your code.

For example, 12 / 100 will be 0, so net = net - ((12 / 100) * gross) equates to net = net - (0 * gross), which is the same as net = net - you haven't changed the "some random value minus 20" value at all.
 
Share this answer
 
Comments
CPallini 6-Dec-22 9:35am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900