一个好玩的猜大小赌博游戏

#include   
#include   
#include  
#include 
int main(int argc, char **argv)  
{  
    int money = 10,a,s,i;
	char flag='\0',dx;
	printf("你有10块钱\n定个小目标吧:比方说赚他个一百块钱!\n想不想试试骰子?(Y/N)");
rerestart:
	scanf("%c",&flag);
	rewind(stdin);
	system("cls");
	if('N' == flag||'n' == flag)
	{
		printf("拿着你的十块钱滚蛋吧!懦夫!\n");
		return 0;
	}
	else
	{
		for(i = 1;;i++)
		{
restart:
			printf("第%d次赌博你要下注:",i);
			scanf("%d",&s);
			rewind(stdin);
			if(s > money)
			{
				printf("小伙子,我可是不允许你欠钱的!\n");
				goto restart;
			}
			else
			{
error:
				printf("你要猜大还是猜小?(D/X)");
				scanf("%c",&dx);
				rewind(stdin);
				srand((unsigned int)(time(NULL)));
				a = rand()%6+1;
				printf("骰子飞速转动...结果为:%d点!\n",a);
				if(a>3&&'d' == dx||a>3&&'D'==dx||a<4&&'x'==dx||a<4&&'X'==dx)
				{
					money += s;
					if(money>=100)
					{
						printf("你在第%d轮赢到了100块,好样的!\n",i);
						return 0;
					}
					else
					{
						printf("不错!这一轮你赢了%d块钱,当前余额:%d元\n",s,money);
					}
				}
				else if(a<4&&'d' == dx||a<4&&'D'==dx||a>3&&'x'==dx||a>3&&'X'==dx)
				{
					money += -s;
					if(money<=0)
					{
						printf("很可惜,你在第%d轮输掉了你所有的钱......",i);
						money = 10;
						printf("想试试东山再起的感觉吗?(Y/N)");
						rewind(stdin);
						goto rerestart;
					}
					else
					{
						printf("很遗憾,这一轮你输了%d块钱,当前余额:%d元\n",s,money);
					}
				}
				else
				{
					printf("输入错误!重新输入:\n");
					goto error;
				}
			}
		}
	}
    return 0;  
}

 

你可能感兴趣的:(C语言,猜大小)