【发布时间】:2016-05-22 16:16:07
【问题描述】:
我正在从“Jumping into c++”一书中学习 c++,在枚举和 switch-case 章节之后,它说我们应该编写一个 Tictactoe 游戏。
我通过声明包含三个状态的 tictactoe 枚举器来编写游戏,即空白、o 和 x,并将 9 个棋盘位置声明为空白。但在测试程序后,我发现我无法将板位置从空白更改为任何东西。这是我的错误还是枚举的工作方式?
例如:
enum Tictactoe{
TTT_O,
TTT_X,
TTT_Blank};
Tictactoe Board1 = TTT_Blank;
//goes all the way until board position 9
int input;
cout << "X, chose a pile which you want to mark << endl;
cin>> input;
switch (input) {
case 1: { Tictactoe Board1 = TTT_X; break; }
//again, goes all the way until all the board positions are checked.
在代码中,它确实每 2 步打印一次棋盘,但它总是将所有棋盘位置显示为空白。
【问题讨论】:
-
请学习如何创建一个Minimal, Complete, and Verifiable Example,您可以向我们展示,它会更容易为您提供帮助。
-
您能否至少展示一下您尝试过的操作,因为您不清楚枚举的哪一部分。
-
不,这不是枚举的工作方式。是的,这是代码中的错误。
标签: c++ enums codeblocks enumeration