home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / CTUTOR / ANSWERS.ZIP / CH02_1.CPP < prev    next >
C/C++ Source or Header  |  1990-07-20  |  848b  |  37 lines

  1.                               // Chapter 2 - Programming exercise 1
  2. #include "iostream.h"
  3.  
  4. enum game_result {win, lose, tie, cancel, forfeit};
  5.  
  6. main()
  7. {
  8. game_result result;
  9. enum game_result omit = cancel;
  10.  
  11.    for (result = win;result <= forfeit;result++) {
  12.       if (result == forfeit)
  13.          cout << "We had to forfeit the game\n";
  14.       else if (result == omit) 
  15.          cout << "The game was cancelled\n";
  16.       else {
  17.          cout << "The game was played ";
  18.          if (result == win)
  19.             cout << "and we won!";
  20.          if (result == lose)
  21.             cout << "and we lost.";
  22.          cout << "\n";
  23.       }
  24.    }
  25. }
  26.  
  27.  
  28.  
  29.  
  30. // Result of execution
  31. //
  32. // The game was played and we won!
  33. // The game was played and we lost.
  34. // The game was played
  35. // The game was cancelled
  36. // We had to forfeit the game
  37.