ch02_1.cpp

来自「Since the field of object oriented progr」· C++ 代码 · 共 37 行

CPP
37
字号
                              // Chapter 2 - Programming exercise 1
#include <iostream.h>

enum game_result {WIN, LOSE, TIE, CANCEL, FORFEIT};

void main()
{
game_result result;
enum game_result omit = CANCEL;
int index;

   for (index = WIN ; index <= FORFEIT ; index++) {
      result = (game_result)index;
      if (result == omit) 
         cout << "The game was cancelled\n";
      else {
         cout << "The game was played ";
         if (result == WIN)
            cout << "and we won!";
         if (result == LOSE)
            cout << "and we lost.";
         if (result == FORFEIT)
            cout << "and we won by forfeit.";
         cout << "\n";
      }
   }
}


// Result of execution
//
// The game was played and we won!
// The game was played and we lost.
// The game was played
// The game was cancelled
// The game was played and we won by forfeit.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?