投骰子

include

include

using namespace std;
//掷骰子,计算和数,输出和数
int rollDice()
{
int die1=1+rand()%6;
int die2=1+rand()%6;
int sum=die1+die2;
cout<<"player rolled"< 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 "< break;
}
while(status==PLAYING){
sum=rollDice();
if(sum==mypoint)
status=WIN;
else if(sum==7)
status=LOSE;
}
if(status==WIN)
cout<<"player wins"< else
cout<<"player loses"< return 0;
}

你可能感兴趣的:(投骰子)