#include <stdio.h>
#include <string.h>
#define MIDDLE_FLAG 1
#define INITIAL_SCORE 1000
int bet()
{
int rollresult
rollresult = rand()%6 + 1 //此处rand()为随机数,对6取余结果为0~5,需要+1修正为1~6
//printf("结果:%-4d",rollresult)
if (rollresult >MIDDLE_FLAG)
return 1
else
return 0
}
int main()
{
int betscore,myscore = INITIAL_SCORE
int resultflag, betflag, betresult
char cinput[2], sresult[3]
printf("您的初始分数为%d\n",myscore)
srand((int)time(0)) //用时间创建随机数种子
while(1)
{
while(1)
{
puts("请压分:")
scanf("%d",&betscore)
if(betscore >myscore)
printf("您的剩余分数不够,为%d", myscore)
else
break
}
fflush(stdin) //强制刷新缓冲区,防止上次输出影响
puts("请选择大小G为大L为小,X为退出:")
gets(cinput)
cinput[0] = cinput[0]%32+'A' - 1
if(cinput[0] == 'X')
break
else
betflag = (cinput[0] == 'G')?1:0
//三目运算符“?”用法:x=(a>b)?a:b相当于if(a>b)x=aelse x=b
betresult = bet()
myscore = (betresult == betflag)?(myscore+2*betscore):(myscore-betscore)
strcpy(sresult, ((betresult!=0)?"大":"小"))
printf("结果为%s,您当前的分数为%d\n",sresult, myscore)
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)