c++初学代码运行有点问题,应该输出四种结果但会输出六种 其中TEM结果输出了三次 求教是哪里出问题了
//设某次体育比赛结果有四种可能WINLOSTTIMCANCEL使用枚举类型编写程序输出这四种情况#include<iostream>usingnamespacestd;...
//设某次体育比赛结果有四种可能 WIN LOST TIM CANCEL 使用枚举类型编写程序输出这四种情况#include<iostream>using namespace std;int main(){ enum GameResult {WIN,LOST,TEM,CANCEL}; GameResult result; GameResult omit=CANCEL; for(int count=WIN;count<=CANCEL;count++) { result=GameResult(count); if(result==omit) cout<<"the game was played an we cancelled." <<endl; else{ cout<<"the game was played."<<endl; if(result==WIN) cout<<"the game was played and we won."<<endl; if(result==LOST) cout<<"the game was played and we losted."<<endl; cout<<endl; } } system("pause"); return 0; }
展开
展开全部
要用 if () { } else if () { } else if () { } else {}; 这种语法结构。
for(int count=WIN;count<=CANCEL;count++) {
result=GameResult(count);
if(result==omit) cout<<"the game was played an we cancelled." <<endl;
else if(result==WIN) cout<<"Case WIN: the game was played and we won."<<endl;
else if(result==LOST) cout<<"Case LOST: the game was played and we losted."<<endl;
else { cout<<"Case TEM: the game was played."<<endl; }
cout<<endl;
}
for(int count=WIN;count<=CANCEL;count++) {
result=GameResult(count);
if(result==omit) cout<<"the game was played an we cancelled." <<endl;
else if(result==WIN) cout<<"Case WIN: the game was played and we won."<<endl;
else if(result==LOST) cout<<"Case LOST: the game was played and we losted."<<endl;
else { cout<<"Case TEM: the game was played."<<endl; }
cout<<endl;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询