Ask Question
11 January, 22:16

Consider the following code segment.

int quant = 20; int unitPrice = 4; int ship = 8; int total; if (quant > 10) { unitPrice = 3; } if (quant > 20) { ship = 0; } total = quant * unitPrice + ship;

What is the value of total after this code segment has been executed?

+1
Answers (1)
  1. 11 January, 23:36
    0
    The value of the total will be 68.

    Explanation:

    We start from the top of the code

    The variables are initialized, depending on these values we will follow the execution of the if statements.

    Is quant > 10? → Since quant is equal to 20, this is true. Since this is true, unitPrice is set to 3.

    Is quant > 20? → Since quant is equal to 20, this is false. Since this is false, ship is not set to 0 (ship remains 8).

    total = quant * unitPrice + ship; → total is (20*3) + 8 → 68
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Consider the following code segment. int quant = 20; int unitPrice = 4; int ship = 8; int total; if (quant > 10) { unitPrice = 3; } if ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers