投骰子

include

include

using namespace std;
//掷骰子,计算和数,输出和数
int rollDice()
{
int die1=1+rand()%6;
int die2=1+rand()%6;
int sum=die1+die2;
cout<<"player rolled"<<die1<<"+"<<die2<<"="<<sum<<endl;
return sum;
}
enum GameStatus {WIN,LOSE,PLAYING};
int main()
{
int sum,mypoint;
GameStatus status;
unsigned seed;
cout<<"please enter an unsigned integer:";
cin>>seed;//输入随机数种子
srand(seed);//将种子传递给rand()
sum=rollDice();//第一轮投骰子,计算和数
switch (sum){
case 7:case 11:
status=WIN;
break;
case 2:case 3:case 12:
status=LOSE;
break;
default:
status=PLAYING;
mypoint =sum;
cout<<"point is "<<mypoint<<endl;
break;
}
while(statusPLAYING){
sum=rollDice();
if(sum
mypoint)
status=WIN;
else if(sum7)
status=LOSE;
}
if(status
WIN)
cout<<"player wins"<<endl;
else
cout<<"player loses"<<endl;
return 0;
}

posted @ 2018-03-24 17:48  雪卿狂  阅读(531)  评论(0编辑  收藏  举报