正确使用枚举

时间:2016-04-19 22:00:18

标签: enums

想知道为什么我不能使用以下代码。

enum  player_state { fast, slow, focus, bust, out};




if (score >= 100)
        player_state = fast;
    else if (score > 50)
        player_state = slow;
    else if ((score <= 50) && (score > 1))
        player_state = focus;
    else if ((score == 1) || (score < 0))
        player_state = bust;
    else
        player_state = out;

我在作业中遇到错误(=)。

任何提示?我以为我可以做这样的事情,如果不是这样的话。

1 个答案:

答案 0 :(得分:0)

枚举是一种类型声明。您必须创建一个使用该类型的变量。 例如

enum  player_states { fast, slow, focus, bust, out};
player_states playerState = fast;