Ask Question
5 March, 19:57

What is the value of the cost variable after the following code snippet is executed? int cost = 82; if (cost 50) { cost = cost * 2; } if (cost < 100) { cost = cost - 20; }

+1
Answers (1)
  1. 5 March, 22:25
    0
    184

    Explanation:

    Given the codes

    int cost = 82; if (cost <100) { + 10; }if (cost> 50) { cost = cost * 2; } if (cost < 100) { cost = cost - 20; }

    The initial value of cost is 82.

    The if condition in Line 3 will pass and therefore cost = 82 + 10 = 92

    The if condition in Line 8 will pass and therefore cost = 92 * 2 = 184

    The if condition in Line 13 will fail l and therefore the if block will be skipped.

    At last, the we get cost = 184.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What is the value of the cost variable after the following code snippet is executed? int cost = 82; if (cost 50) { cost = cost * 2; } 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