代码:
//2_9.cpp
//设某次体育比赛的结果有四种可能,WIN,LOSE,TIE,CANCEL.输赢平退出。
#include <iostream>
using namespace std;
enum GameResult{WIN,LOSE,TIE,CANCEl};
int main() {
GameResult result;
enum GameResult omit= CANCEl;
for (int count = WIN; count <= CANCEl; count++) {
result = GameResult(count);
if (result == omit) {
cout << "the game is cancel";
}
else
{
cout << "the game is played";
if (result == WIN) {
cout << "and we win!";
}
if (result == LOSE) {
cout << "and we lose ";
}
if (result == TIE) {
cout << "and we tie";
}
cout << endl;
}
}
return 0;
}
运行结果: