Chapter 5: Decisions

Sequences of Comparisons

if (condition)
{
  statement(s)
}
else if (condition)
{
  statement(s)
}
else if (condition)
{
  statement(s)
}
...
else
{
  statement(s)
}

Nested Ifs

There are an infinite number of possibilities. Here is one.

if (condition)
{
  if (condition)
  {
    statement(s)
  }
  else (condition)
  {
    statement(s)
  }
}
else
{
  statement(s)
}

Program Development Process

  1. Design
  2. Develop test cases
  3. Type in program, fix compiler errors
  4. Run program on test cases, debug as necessary

Lecture Code

Design a program to calculate a Montana State student's tuition fee. The student can be an undergraduate or a graduate, can be taking 1-3 credits, and can be either resident or non-resident. Here is the relevant tuition table.

Program 1 Solution

Lab 4 Solution

Valid XHTML 1.0!