Skip to main content

Section 5.8 Selection-WE4-P1

Subgoals for Evaluating Selection Statements.

  1. Diagram which statements go together
  2. For if statement, determine whether expression is true or false
  3. If true – follow true branch, if false – follow else branch or do nothing if no else branch

Subsection 5.8.1

Exercises Exercises

1.
Use this given setup for each of the questions below.
int alpha = 2;
int beta = 1;
int delta = 3;
int eta = 0;
int gamma = 0;
2.
Q12: After executing the following code, the value in variable gamma is and the value in variable eta is .
if (alpha < delta)
    gamma = alpha + 5;
else
    gamma = beta + 5;
    eta = beta + 2;
3.
Q13: After executing the following code, the value in variable gamma is and the value in variable eta is .
if (alpha > beta)
{
    eta = alpha + 2;
    gamma = alpha + 5;
}
else
{
    eta = alpha - 1;
    gamma = beta - 1;
}
You have attempted of activities on this page.