|
发表于 2020-10-10 12:08:13
|
显示全部楼层
本楼为最佳答案
本帖最后由 风过无痕1989 于 2020-10-10 13:27 编辑
你的错误,已经帮你修改了,现在可以玩了
- #include<stdio.h> // stdio.h 头文件是系统自带,用尖括号,不用引号
- #include<conio.h> // getch() 需要这个头文件
- void main()
- {
- int total = 21;
- int shengyu,yours,computer;
- char another;
-
- printf("****************************************\n");
- printf("***** 起始牙签个数为%d *****\n",total);
- printf("***** 每次只能拿走1-3个 *****\n");
- printf("***** 谁拿最后一个谁就输了 *****\n");
- printf("\n");
- printf("\n明白了?按任意键开始吧......");
-
- getch(); // 没有添加头函数 conio.h
- shengyu = total;
- while(shengyu != 0)
- {
- do //只能拿1-3个
- {
- printf("\n当前牙签数为%d\n",shengyu);
- printf("请输入你拿走的牙签数(1-3): ");
- scanf("%d",&yours);
- if(yours >= 1 && yours <= 3)
- break;
- else
- printf("你每次只能拿1到3个。\n");
- }while(1);
-
- shengyu = shengyu - yours;
- if(shengyu < 0)
- {
- printf("\n\n你不按规则来呀! \n");
- shengyu = shengyu + yours;
- continue;
- }
- if(shengyu == 0)
- {
- printf("你输了,再来不? (Y/N)");
- //清缓冲区
- fflush(stdin);
- another = getchar();
-
- if(another =='Y' || another == 'y')
- {
- shengyu = total;
- }
- else
- {
- printf("\n\n再见,以后再来玩呀!\n");
- break;
- }
- }
- else
- {
- computer = 4 - yours;
- printf("\n电脑拿走了%d个牙签\n",computer);
- shengyu = shengyu - computer;
- }
- }
- }
复制代码 |
|