#include
#include
#include
int rollDice( void );
int main()
{
enum Status{ CONTINUE,WON,LOST};
int sum,myPoint;
Status gameStatus;//status有什么用呢?
srand(time (NULL));//为什么要设这行?
sum=rollDice();
switch (sum) {
case 7:
case 11:
gameStatus=WON;
break;
case 2:
case 3:
case 12:
gameStatus=LOST;
break;
default:
gameStatus=CONTINUE;
myPoint=sum;
cout<<"point is"< break;
}
while(gameStatus==CONTINUE){
sum=rollDice();
if(sum==myPoint)
gameStatus=WON;
else
if(sum==7)
gameStatus=LOST;
}
if(gameStatus==WON)
cout<<"player wins"< else
cout<<"player losts"< return 0;
}
int rollDice(void )//为什么要用void,不是有个返回值吗?
{
int die1,die2,workSum;
die1=1+rand()%6;
die2=1+rand()%6;
workSum=die1+die2;
cout<<"player rolled"< return workSum;
}
--------------------next---------------------
阅读(1040) | 评论(0) | 转发(0) |