186k views
4 votes
What will be the value of bonus after the following code is executed? int bonus, sales = 85000; char dept = 'S'; if (sales > 100000){ if (dept == 'R') bonus = 2000; else bonus = 1500; else if (sales > 75000) if (dept == 'R') bonus = 1250; else bonus = 1000; else bonus = 0;}

1 Answer

1 vote

Answer:

Bonus=1000

Step-by-step explanation:

The code uses three variables bonus, sales and dept. The values of sales and dept are set to 85000(integer) and S(character) respectively.

The code then uses nested if-else statements to determine the value of bonus depending on the value of sales and dept. The value of bonus is determined as follows:

1. If the value of sales is greater than 100,000, then the first condition (sales >100000) becomes true and the following set of conditions on the value of dept are analyzed. If dept equals to the character 'R' then bonus is set to 2000 otherwise bonus=1500.

2. If the value of sales is greater than 75000, but less than or equal to 100,000, then the second condition (sales>75000) becomes true and the following set of conditions on dept are analyzed. If dept equals to the character 'R' then bonus is set to 1250 otherwise bonus=1000.

3. If the value of sales is less than or equal to 75000, then the statements after else are executed which sets bonus=0.

However, in our case as sales=85000 which is greater than 75000 less than 100, 000, the second condition is met. Moreover, as value of dept = 'S' and not 'R', bonus is equal to 1000.

User Crrlos
by
3.4k points