Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(6 POINTS) What value is assigned to SATURATION by the two if-else if statements

ID: 3590402 • Letter: #

Question

(6 POINTS) What value is assigned to SATURATION by the two if-else if statements when X = 1.5, respectively? (1) if (X > 0.0) (2) if (X > 2.0) SATURATION = 0.0; SATURATION =2.0; if (X > 1.0) if (X > 1.0) SATURATION = 1.0; SATURATION = 1.0; if (X > 2.0) if (X > 0.0) SATURATION = 2.0; SATURATION = 0.00; when X = 1.5, SATURATION = when X = 1.5, SATURATION =

6. (6 POINTS) What value is assigned to SATURATION by the two if-else if statements when X = 1.5, respectively? (1) if (X > 0.0) if (x 1.0) if (x> 2.0) SATURATION = 0.0; SATURATION = 1.0; SATURATION = 2.0; (2) if (x > 2.0) if (x 1.0) if (x > 0.0) SATURATION -2.0; SATURATION = 1.0; SATURATION = 0.00; when X = 1.5, SATURATION when X = 1.5, SATURATION =

Explanation / Answer

(1)

When X = 1.5

The first if statement is executed as 1.5 > 0.0 . Hence, SATURATION = 0.0.

The second if statement is executed as 1.5 > 1.0 . Hence, SATURATION = 1.0.

The third if statement is not executed as 1.5 < 2.0

Hence, the value of SATURATION = 1.0.

(2)

When X = 1.5

The first if statement is not executed as 1.5 < 2.0.

The second if statement is executed as 1.5 > 1.0 . Hence, SATURATION = 1.0.

The third if statement is s executed as 1.5 > 0.0 . Hence, SATURATION = 0.0

Hence, the value of SATURATION = 0.0