188k views
4 votes
After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time? 15 10 25 0 5

1 Answer

5 votes

Question:

After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time?

cin>> input_value;

if (input_value >5)

input_value = input_value+5;

else if (input_value > 2)

input_value= input_value+10;

else

input_value= input_value + 15;

Answer:

input_value= 15

Step-by-step explanation:

Line 1 of the program gets the value of user_input

i.e user_input = 0

Line 2 checks if user_input is greater than 5, since this is false, the program jumps to line 4

Line 4 checks if user_input is greater than 2, since this is also false, the program jumps to line 6

The instruction on line 6 implies that, if the previous conditions are false, then line 7 be executed.

So:

input_value= input_value + 15;

input_value= 0 + 15

input_value= 15

Hence, input_value is 15

User Matthew Schuchard
by
6.3k points