Table Of Contents
Previous Section Next Section

Chapter 4: Everyday Problems

Every day programmers create new programs. Every day these programmers make mistakes. These aren't the simple mistakes of the novice and aren't complex enough to be considered advanced problems. These bugs are, well, your everyday bugs.

Program 27: "and" and "and and"

This program is designed to test to see if two numbers are non-zero. The problem is that the programmer used a little too much shorthand, and something is going wrong:

  1 /************************************************
  2  * if_test -- Simple test of the if statement.  *
  3  ************************************************/
  4 #include <iostream>
  5
  6 int main()
  7 {
  8     int i1 = 12;        // A number
  9     int i2 = 3;         // Another number
 10
 11     if (i1 & i2)
 12         std::cout << "Both numbers are non-zero\n";
 13     else
 14         std::cout << "At least one number is zero\n";
 15     return (0);
 16 }

(Next Hint 351. Answer 17.)

Table Of Contents
Previous Section Next Section