Skip to main content

Section 5.2 Selection-WE1-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.2.1

Each question below is independent, but they all use this given setup
int alpha = 2;
int beta = 1;
int delta = 3;
int eta = 0;
int gamma = 0;

double omega = 2.5;
double theta = -1.3;
double kappa = 3.0;
double lambda = 0.0;
double rho = 0.0;

Exercises Exercises

1.
Q1: What is the value of rho after executing the following code?
if (theta > omega)
    rho = kappa + 2;
2.
Q2: What is the value of eta after executing the following code?
if (beta < alpha)
    eta = 42;
3.
Q3: After executing the following code, the value in variable eta is and the value in variable beta is .
if (kappa < delta)
    eta = 42;
    beta = 22;
4.
Q4: After executing the following code, the value in variable eta is and the value in variable beta is .
if (gamma < kappa)
{
    beta = 22;
}
eta = 42;
5.
You have attempted of activities on this page.