Table Of Contents
Previous Section Next Section

Program 18: Classic

If you are a programmer, you've made the mistake contained in this program. If you're becoming a programmer, you will make this mistake. And it will drive you nuts until you figure out what it is.

So what does this program do:

  1 /************************************************
  2  * Test the logic for a simple accounting       *
  3  *      program.                                *
  4  ************************************************/
  5 #include <iostream>
  6
  7 int main()
  8 {
  9     // Amount owed (if any) by the user
 10     int amount;
 11
 12     std::cout << "Enter current balance: ";
 13     std::cin >> amount;
 14
 15     if (amount = 0)
 16         std::cout << "You owe nothing\n";
 17     else
 18         std::cout << "You owe " << amount << "\n";
 19
 20     return (0);
 21 }

(Next Hint 155. Answer 47.)

Table Of Contents
Previous Section Next Section