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

Respuesta :

Answer:

184

Explanation:

Given the codes

  1.        int cost = 82;
  2.        if (cost < 100)
  3.        {
  4.            cost = cost + 10;
  5.        }
  6.        if (cost > 50)
  7.        {
  8.            cost = cost * 2;
  9.        }
  10.        if (cost < 100)
  11.        {
  12.            cost = cost - 20;
  13.        }

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.