Ask Question
13 September, 01:42

What will be the value of bonus after the following code is executed? a. int bonus, sales = 10000; b. if (sales < 5000) bonus = 200; c. else if (sales < 7500) bonus = 500; d. else if (sales < 10000) bonus = 750; e. else if (sales < 20000) bonus = 1000; f. else bonus = 1250;

+3
Answers (1)
  1. 13 September, 03:05
    0
    bonus=1000

    Explanation:

    Let's go line by line, I will add an explanation after each line

    a. int bonus, sales = 10000;

    In a., bonus is initialized and sales is equal to 10000

    b. if (sales < 5000) bonus = 200;

    Here we set bonus equal to 200 only if sales is less than 5000. As sales is not less than 5000 then we omit this instruction and continue with the next statement or block of code

    c. else if (sales < 7500) bonus = 500;

    Here we set bonus equal to 500 only if sales is less than 7500. As sales is not less than 7500 then we omit this instruction and continue with the next statement or block of code

    d. else if (sales < 10000) bonus = 750;

    Here we set bonus equal to 750 only if sales is less than 10000. And here is something important. the 'less than' (<) operator does not include the value we are comparing our variable with. As sales is not less than 10000 then we omit this instruction and continue with the next statement or block of code

    e. else if (sales < 20000) bonus = 1000;

    Here we set bonus equal to 1000 only if sales is less than 20000. As sales is indeed less than 20000 then this statement is true and we set bonus equal to 1000

    f. else bonus = 1250;

    Here we set bonus equal to 1250 only if none of the above if statements are true. As our statement in line e. is true, we omit this instruction
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What will be the value of bonus after the following code is executed? a. int bonus, sales = 10000; b. if (sales < 5000) bonus = 200; c. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers