学C的时候没学这个枚举类型(没用到),现在跟着C++的书系统的学了一下。
而且这一趟写下来对cout的运用更熟练了;顺便学了点英语
omit 遗漏
tie with 和···成平局
We are even.我们是平局\我们两清了。
#include<iostream>
using namespace std;
enum Gameresult {WIN,LOSE,TIE,CANCEL};
/*联想到了struct类型 是一样的结构
所以现在理解enum会更轻松一点.
声明一个enum类型的Gameresult结构体(?之类的东西),
内含四个变量,没有赋值的情况下自动赋值0,1,2````*/
int main() {
enum Gameresult result;
Gameresult omit = CANCEL;
/*Gameresult类型的两个变量,result没有初始化*/
for (int count = WIN; count <= CANCEL; count++) {
result = Gameresult(count);
if (result == omit)
cout << "The game was cancelled!";
else {
cout << "The game was played and ";
if (result == WIN)
cout << "we won!";
else if (result == TIE)
cout << "we were even!";
else
cout << "we lost.";
}
cout << endl;
/*和之前是同一个点 连续cout不换行*/
}
return 0;
}
附运行结果