home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / tutorial / cpptutor / source / enum.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-15  |  780 b   |  37 lines

  1.                                   // Chapter 2 - Program 1 - ENUM.CPP
  2. #include <iostream.h>
  3.  
  4. enum game_result {WIN, LOSE, TIE, CANCEL};
  5.  
  6. void main()
  7. {
  8. game_result result;
  9. enum game_result omit = CANCEL;
  10. int index;
  11.  
  12.    for (index = WIN ; index <= CANCEL ; index++) {
  13.       result = (game_result)index;
  14.       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.  
  37.