15,942,144 members
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;
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);
}
return 0;
}```
Posted
Updated 6-Dec-22 3:03am
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.

## Solution 1

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.