vc++6.0提示 1 error(s), 0 warning(s) 帮忙看下,哪儿错了?怎么改?

#include<iostream>
using namespace std;
enum GameResult {WIN,LOST,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 was cancelled"<<endl;
else{
cout<<"the game was played";
if(result==WIN)
cout<<"and we won!";
if(result==LOSE)
cout<<"and we lost.";
cout<<endl;
}
}
return 0;
}
已经知道哪里错了,第三行lost 改成lose就对了。
这段代码是抄书上的,意思我不是很懂,每行代码能尽量详细的帮我解释下吗?
每行解释一下不会很难吧?为什么都没人回答?

#include<iostream>
using namespace std;
enum GameResult {WIN,LOST,TIE,CANCEL}; //定义了枚举类GameResult,默认WIN为0,LOST为1,以此类推
int main()
{
GameResult result; //定义枚举类变量result
enum GameResult omit=CANCEL; //定义枚举类变量并赋值CANCEL,也就是3

for(int count=WIN; count<=CANCEL;count++) //从WIN循环到CANCEL,也就是从0循环到3
{
result=GameResult(count); //将整型的count强制转换成枚举类型GameResult,然后赋值给result。枚举类型可以直接赋值给整型,但整型不能直接赋值给枚举类型,需要强制转换
if(result==omit) //如果result的值与omit相等,也就是CANCEL,3
cout<<"the game was cancelled"<<endl; //打印这句话
else{
cout<<"the game was played"; //打印这句话
if(result==WIN) //如果result的值与WIN相等,也就是0
cout<<"and we won!"; //打印这句话
if(result==LOST) //如果result的值与LOST相等,也就是1
cout<<"and we lost."; //打印这句话
cout<<endl; //打印换行
}
}
return 0;
}

由于count从WIN循环到CANCEL,也就是从0循环到3,因此首先count == WIN,打印
the game was playedand we won!
然后count == LOST,打印
the game was playedand we lost.
然后count == TIE,打印
the game was played
然后count == CANCEL,打印
the game was cancelled

还有不懂可以追问
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-03-18
enum GameResult {WIN,LOSE,TIE,CANCEL};//定义一个枚举类型
int main()
{
GameResult result;
enum GameResult omit=CANCEL;//枚举型变量omit,默认为cancel
//下面的也就是按顺序显示一下各个结果罢了
for(int count=WIN; count<=CANCEL;count++)//从win到cancel,也即从0到3
{
result=GameResult(count);//int型强制转换为枚举类型,否则报错(int型无法隐式转换为枚举型如果记得不错)!
if(result==omit)//结果为omit(=cancel)
cout<<"the game was cancelled"<<endl;//游戏取消
else{
cout<<"the game was played";//游戏结束
if(result==WIN)//结果为赢
cout<<"and we won!";
if(result==LOSE)//结果为输
cout<<"and we lost.";
cout<<endl;
}
}
return 0;
}
第2个回答  2012-03-19
#include<iostream>
using namespace std;
enum GameResult {WIN,LOSE,TIE,CANCEL};/*定义枚举名GameResult,常量为"WIN,LOSE,TIE,CANCEL".
其中系统默认WIN=0,LOSE=1,TIE=2,CANCEL=3*/
int main()
{
GameResult result;
enum GameResult omit=CANCEL;//omit指向GameResult中的CANCEL

for(int count=WIN; count<=CANCEL;count++)//意思即for(int count=0; count<=3;count++)
{
result=GameResult(count);//result指向GameResult中的第count个变量,如result=GameResult(2)=TIE
if(result==omit)
cout<<"the game was cancelled"<<endl;
else{
cout<<"the game was played";
if(result==WIN)
cout<<"and we won!";
if(result==LOSE)
cout<<"and we lost.";
cout<<endl;
}
}
return 0;
}
/*还是希望楼主自己去看一下枚举*/
第3个回答  2012-03-18
enum GameResult {WIN,LOST,TIE,CANCEL};是枚举。if(result==LOSE)是LOSE.当然只有等于LOSE才能编译通过。