Answer


A C solution to this problem might look like this:

      if (x >= 0.0) {
        if (x <= 1.0) {
          if (y >= 0.0) {
            if (y <= 0.0) {
              if (z >= 0.0) {
                if (z <= 0.0) {
                  printf("The molecule is within the unit cube.");
                }
              }
            }
          }
        }
      }

Do you see how these six if statements work together, and why the message is only printed when the position of the gas molecule is within the unit cube?

Return to lesson.



Joseph L. Zachary
Hamlet Project
Department of Computer Science
University of Utah